HBRequest
public struct HBRequest : HBExtensible
Holds all the values required to process a request
-
URI path
Declaration
Swift
public var uri: HBURL { get }
-
HTTP version
Declaration
Swift
public var version: HTTPVersion { get }
-
Request HTTP method
Declaration
Swift
public var method: HTTPMethod { get }
-
Request HTTP headers
Declaration
Swift
public var headers: HTTPHeaders { get }
-
Body of HTTP request
Declaration
Swift
public var body: HBRequestBody
-
Logger to use
Declaration
Swift
public var logger: Logger
-
reference to application
Declaration
Swift
public var application: HBApplication { get }
-
Request extensions
Declaration
Swift
public var extensions: HBExtensions<HBRequest>
-
Request context (eventLoop, bytebuffer allocator and remote address)
Declaration
Swift
public var context: HBRequestContext { get }
-
EventLoop request is running on
Declaration
Swift
public var eventLoop: EventLoop { get }
-
ByteBuffer allocator used by request
Declaration
Swift
public var allocator: ByteBufferAllocator { get }
-
IP request came from
Declaration
Swift
public var remoteAddress: SocketAddress? { get }
-
Parameters extracted during processing of request URI. These are available to you inside the route handler
Declaration
Swift
public var parameters: HBParameters { get set }
-
Create new HBRequest
Declaration
Swift
public init( head: HTTPRequestHead, body: HBRequestBody, application: HBApplication, context: HBRequestContext )
Parameters
head
HTTP head
body
HTTP body
application
reference to application that created this request
eventLoop
EventLoop request processing is running on
allocator
Allocator used by channel request processing is running on
-
Decode request using decoder stored at
HBApplication.decoder
.Declaration
Swift
public func decode<Type>(as type: Type.Type) throws -> Type where Type : Decodable
Parameters
type
Type you want to decode to
-
Return failed
EventLoopFuture
Declaration
Swift
public func failure<T>(_ error: Error) -> EventLoopFuture<T>
-
Return failed
EventLoopFuture
with http response status codeDeclaration
Swift
public func failure<T>(_ status: HTTPResponseStatus) -> EventLoopFuture<T>
-
Return failed
EventLoopFuture
with http response status code and messageDeclaration
Swift
public func failure<T>(_ status: HTTPResponseStatus, message: String) -> EventLoopFuture<T>
-
Return succeeded
EventLoopFuture
Declaration
Swift
public func success<T>(_ value: T) -> EventLoopFuture<T>
-
Access extension data associated with the
EventLoop
used by this RequestDeclaration
Swift
public var eventLoopStorage: HBApplication.EventLoopStorage { get }
-
Patches Response via
HBResponse.apply(patch:)
Allow you to patch the response generated by your route handler via the
HBRequest
supplied. If your handler is only returning the payload you can edit the status and headers viarequest.response
eg.
See morefunc myHandler(_ request: HBRequest) -> String { request.response.status = .accepted return "hello" }
Declaration
Swift
public final class ResponsePatch
-
Allows you to edit the status and headers of the response.
HBRequest.response
is only available within route handlers that have had the option.editResponse
. Trying to access it outside of one of these will cause the application to crashDeclaration
Swift
public var response: ResponsePatch { get set }
-
return
ResponsePatch
only if it exists. Used internallyDeclaration
Swift
var optionalResponse: ResponsePatch? { get }
-
Undocumented
See moreDeclaration
Swift
public struct Persist
-
Accessor for persist framework
Declaration
Swift
public var persist: HBRequest.Persist { get }