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.

Member variables

  • 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

Initialization

Methods

  • 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

Configuration

EventLoopStorage

  • Extend EventLoopStorage using HBExtensions.

    Use this to add additional data to each EventLoop in the application EventLoopGroup.

    extension HBApplication.EventLoopStorage {
        var myVar: String {
            get { extensions.get(\.myVar) }
            set { extensions.set(\.myVar, value: newValue) }
        }
    }
    

    You can access the extension via HBApplication.eventLoopStorage(for: eventLoop).myVar or if you have an HBRequest you can access the extension via HBRequest.eventLoopStorage.myVar.

    See more

    Declaration

    Swift

    public final class EventLoopStorage
  • Provide access to EventLoopStorage from EventLoop.

    See more

    Declaration

    Swift

    public struct EventLoopStorageMap
    extension HBApplication.EventLoopStorageMap: Sequence
  • EventLoopStorageMap for Application.

    Declaration

    Swift

    public private(set) var eventLoopStorage: EventLoopStorageMap { get set }
  • Get EventLoopStorage for EventLoop

    Declaration

    Swift

    public func eventLoopStorage(for eventLoop: EventLoop) -> EventLoopStorage
  • Allow the application to attach data to each EventLoop

    Declaration

    Swift

    public func addEventLoopStorage()

HTTPResponder

  • HTTP responder class for Hummingbird. This is the interface between Hummingbird and HummingbirdCore

    The HummingbirdCore server calls respond to get the HTTP response from Hummingbird

    See more

    Declaration

    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 more

    Declaration

    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