Contents

stanfordspezi/spezivapor

This source file is part of the Stanford Spezi open source project

Overview

SpeziVapor provides seamless integration between the Spezi framework and Vapor web applications, allowing you to leverage Spezi's modular architecture in your server-side Swift code.

Configuration

Configure Spezi during your Vapor application setup:

import SpeziVapor
import Vapor

func configure(_ app: Application) throws {
    app.spezi.configure(standard: MyStandard()) {
        ModuleA()
        ModuleB()
    }
}

[!IMPORTANT] Spezi must be configured before accessing any modules. Attempting to access modules before configuration will result in a runtime error.

Usage

Access configured modules in your route handlers via req.spezi:

app.get("users") { req async throws -> [UserData] in
    let dataModule = req.spezi[DataModule.self]
    return dataModule.getAllUsers()
}

Thread Safety

All modules accessed through SpeziVapor must conform to Module and Sendable for safe concurrent access:

actor MyModule: Module, Sendable {
    func getData() -> [String] {
        // ...
    }
}

[!WARNING] Loading or unloading modules after initial configuration can lead to data races. Configure all modules once during application startup.

Installation

The project can be added to your Xcode project or Swift Package using the Swift Package Manager.

Xcode: For an Xcode project, follow the instructions on adding package dependencies to your app.

Swift Package: You can follow the Swift Package Manager documentation about defining dependencies to add this project as a dependency to your Swift Package.

License

This project is licensed under the MIT License. See Licenses for more information.

Contributors

This project is developed as part of the Stanford Mussallem Center for Biodesign at Stanford University. See CONTRIBUTORS.md for a full list of all Spezi Vapor contributors.

[Stanford Mussallem Center for Biodesign Logo] [Stanford Mussallem Center for Biodesign Logo]

Package Metadata

Repository: stanfordspezi/spezivapor

Default branch: main

README: README.md