Protocols

The following protocols are available globally.

  • An error that is capable of generating an HTTP response

    By conforming to HBHTTPResponseError you can control how your error will be presented to the client. Errors not conforming to this will be returned with status internalServerError.

    See more

    Declaration

    Swift

    public protocol HBHTTPResponseError : Error
  • Protocol for objects generating a HBHTTPResponse from a HBHTTPRequest.

    This is the core interface to the HummingbirdCore library. You need to provide an object that conforms to HBHTTPResponder when you call HTTPServer.start. This object is used to define how you convert requests to the server into responses.

    This is an example HBHTTPResponder that replies with a response with body “Hello”. Once you have your response you need to call onComplete.

    struct HelloResponder: HBHTTPResponder {
        func respond(
            to request: HBHTTPRequest,
            context: ChannelHandlerContext,
            onComplete: @escaping (Result<HBHTTPResponse, Error>) -> Void
        ) {
            let responseHead = HTTPResponseHead(version: .init(major: 1, minor: 1), status: .ok)
            let responseBody = context.channel.allocator.buffer(string: "Hello")
            let response = HBHTTPResponse(head: responseHead, body: .byteBuffer(responseBody))
            onComplete(.success(response))
        }
    }
    

    The following will start up a server using the above HelloResponder.

    let server = HBHTTPServer(
        group: eventLoopGroup,
        configuration: .init(address: .hostname("127.0.0.1", port: 8080))
    )
    try server.start(responder: HelloResponder()).wait()
    
    See more

    Declaration

    Swift

    public protocol HBHTTPResponder
  • Undocumented

    See more

    Declaration

    Swift

    public protocol HBStreamerProtocol
  • Object supplying bytebuffers for a response body

    See more

    Declaration

    Swift

    public protocol HBResponseBodyStreamer
  • HTTPServer child channel initializer protocol

    See more

    Declaration

    Swift

    public protocol HBChannelInitializer