HBRequest

public struct HBRequest : HBExtensible

Holds all the values required to process a request

Member variables

  • uri

    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 }

Initialization

  • 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

Methods

  • 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 code

    Declaration

    Swift

    public func failure<T>(_ status: HTTPResponseStatus) -> EventLoopFuture<T>
  • Return failed EventLoopFuture with http response status code and message

    Declaration

    Swift

    public func failure<T>(_ status: HTTPResponseStatus, message: String) -> EventLoopFuture<T>
  • Return succeeded EventLoopFuture

    Declaration

    Swift

    public func success<T>(_ value: T) -> EventLoopFuture<T>

EventLoopStorage

  • Access extension data associated with the EventLoop used by this Request

    Declaration

    Swift

    public var eventLoopStorage: HBApplication.EventLoopStorage { get }

Response patching

  • 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 via request.response eg.

    func myHandler(_ request: HBRequest) -> String {
        request.response.status = .accepted
        return "hello"
    }
    
    See more

    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 crash

    Declaration

    Swift

    public var response: ResponsePatch { get set }
  • return ResponsePatch only if it exists. Used internally

    Declaration

    Swift

    var optionalResponse: ResponsePatch? { get }
  • Undocumented

    See more

    Declaration

    Swift

    public struct Persist
  • Accessor for persist framework

    Declaration

    Swift

    public var persist: HBRequest.Persist { get }