Structurehummingbird 2.1.0Hummingbird
Application
Application class. Brings together all the components of Hummingbird together
Application.swift:172struct Application<Responder> where Responder : HTTPResponder, Responder.Context : InitializableFromSource, Responder.Context.Source == ApplicationRequestContextSource
let router = Router()
router.middleware.add(MyMiddleware())
router.get("hello") { _ in
return "hello"
}
let app = Application(responder: router.buildResponder())
try await app.runService()
Editing the application setup after calling runService
will produce undefined behaviour.
Citizens in Hummingbird
Conformances
protocol ApplicationProtocol
Protocol for an Application. Brings together all the components of Hummingbird together
protocol Sendable
protocol Service
This is the basic protocol that a service has to implement.
Type members
init(responder: Responder, server: HTTPServerBuilder, configuration: ApplicationConfiguration, services: [Service], onServerRunning: @escaping (Channel) async -> Void, eventLoopGroupProvider: EventLoopGroupProvider, logger: Logger?
) Initialize new Application
init<ResponderBuilder>(router: ResponderBuilder, server: HTTPServerBuilder, configuration: ApplicationConfiguration, services: [Service], onServerRunning: @escaping (Channel) async -> Void, eventLoopGroupProvider: EventLoopGroupProvider, logger: Logger?
) Initialize new Application
Instance members
var configuration: ApplicationConfiguration
Configuration
let eventLoopGroup: EventLoopGroup
var logger: Logger
var processesRunBeforeServerStart: [() async throws -> Void]
Processes to be run before server is started
let responder: Responder
routes requests to responders based on URI
let server: HTTPServerBuilder
Server channel setup
var services: [any Service]
func addServices(any Service...
) Add service to be managed by application ServiceGroup
func beforeServerStarts(perform: @escaping () async throws -> Void
) Add a process to run before we kick off the server service
func buildResponder(
) async throws -> Responder func onServerRunning(Channel
) async
Instance features
func run(
) async throws Construct application and run it
func runService(gracefulShutdownSignals: [UnixSignal]
) async throws Helper function that runs application inside a ServiceGroup which will gracefully shutdown on signals SIGINT, SIGTERM
Citizens in Hummingbird
where Responder:HTTPResponder, Responder.Context:InitializableFromSource, Responder.Context.Source == ApplicationRequestContextSource
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Escapable