Protocols
The following protocols are available globally.
-
An error that is capable of generating an HTTP response
By conforming to
See moreHBHTTPResponseError
you can control how your error will be presented to the client. Errors not conforming to this will be returned with status internalServerError.Declaration
Swift
public protocol HBHTTPResponseError : Error
-
Protocol for objects generating a
HBHTTPResponse
from aHBHTTPRequest
.This is the core interface to the HummingbirdCore library. You need to provide an object that conforms to
HBHTTPResponder
when you callHTTPServer.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 callonComplete
.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
.
See morelet server = HBHTTPServer( group: eventLoopGroup, configuration: .init(address: .hostname("127.0.0.1", port: 8080)) ) try server.start(responder: HelloResponder()).wait()
Declaration
Swift
public protocol HBHTTPResponder
-
Undocumented
See moreDeclaration
Swift
public protocol HBStreamerProtocol
-
Object supplying bytebuffers for a response body
See moreDeclaration
Swift
public protocol HBResponseBodyStreamer
-
HTTPServer child channel initializer protocol
See moreDeclaration
Swift
public protocol HBChannelInitializer