HBApplication
public final class HBApplication : HBExtensible
Application class. Brings together all the components of Hummingbird together
Create an HBApplication, setup your application middleware, encoders, routes etc and then call start
to
start the server and wait
to wait until the server is stopped.
let app = HBApplication()
app.middleware.add(MyMiddleware())
app.get("hello") { _ in
return "hello"
}
app.start()
app.wait()
Editing the application setup after calling start
will produce undefined behaviour.
-
server lifecycle, controls initialization and shutdown of application
Declaration
Swift
public let lifecycle: ServiceLifecycle
-
event loop group used by application
Declaration
Swift
public let eventLoopGroup: EventLoopGroup
-
thread pool used by application
Declaration
Swift
public let threadPool: NIOThreadPool
-
middleware applied to requests
Declaration
Swift
public let middleware: HBMiddlewareGroup
-
routes requests to requestResponders based on URI
Declaration
Swift
public var router: HBRouter
-
http server
Declaration
Swift
public var server: HBHTTPServer
-
Configuration
Declaration
Swift
public var configuration: Configuration
-
Application extensions
Declaration
Swift
public var extensions: HBExtensions<HBApplication>
-
Logger. Required to be a var by hummingbird-lambda
Declaration
Swift
public var logger: Logger
-
Encoder used by router
Declaration
Swift
public var encoder: HBResponseEncoder
-
decoder used by router
Declaration
Swift
public var decoder: HBRequestDecoder
-
Initialize new Application
Declaration
Swift
public init( configuration: HBApplication.Configuration = HBApplication.Configuration(), eventLoopGroupProvider: NIOEventLoopGroupProvider = .createNew )
-
Run application
Declaration
Swift
public func start() throws
-
wait while server is running
Declaration
Swift
public func wait()
-
Shutdown application
Declaration
Swift
public func stop()
-
Construct the RequestResponder from the middleware group and router
Declaration
Swift
public func constructResponder() -> HBResponder
-
shutdown eventloop, threadpool and any extensions attached to the Application
Declaration
Swift
public func shutdownApplication() throws
-
Application configuration
See moreDeclaration
Swift
public struct Configuration
-
Extend EventLoopStorage using HBExtensions.
Use this to add additional data to each
EventLoop
in the applicationEventLoopGroup
.extension HBApplication.EventLoopStorage { var myVar: String { get { extensions.get(\.myVar) } set { extensions.set(\.myVar, value: newValue) } } }
You can access the extension via
See moreHBApplication.eventLoopStorage(for: eventLoop).myVar
or if you have anHBRequest
you can access the extension viaHBRequest.eventLoopStorage.myVar
.Declaration
Swift
public final class EventLoopStorage
-
Provide access to
See moreEventLoopStorage
fromEventLoop
.Declaration
-
EventLoopStorageMap for Application.
Declaration
Swift
public private(set) var eventLoopStorage: EventLoopStorageMap { get set }
-
Get
EventLoopStorage
forEventLoop
Declaration
Swift
public func eventLoopStorage(for eventLoop: EventLoop) -> EventLoopStorage
-
Allow the application to attach data to each EventLoop
Declaration
Swift
public func addEventLoopStorage()
-
HTTP responder class for Hummingbird. This is the interface between Hummingbird and HummingbirdCore
The HummingbirdCore server calls
See morerespond
to get the HTTP response from HummingbirdDeclaration
Swift
public struct HTTPResponder : HBHTTPResponder
-
Context object for Channel to be provided to HBRequest
Declaration
Swift
struct ChannelRequestContext : HBRequestContext
-
Framework for storing persistent key/value pairs between mulitple requests
See moreDeclaration
Swift
public struct Persist
-
Accessor for persist framework
Declaration
Swift
public var persist: Persist { get }
-
Add persist framework to
HBApplication
.Declaration
Swift
public func addPersist(using: HBPersistDriverFactory)
Parameters
using
Factory struct that will create the persist driver when required