Response

public class Response

An HTTP response for an incoming request.

  • Headers to include with the response.

    See also

    HTTPHeaders

    Declaration

    Swift

    public var headers: HTTPHeaders
  • The HTTP status to return with the response.

    Note

    Defaults to 200 OK

    Declaration

    Swift

    public var status: HTTPResponseStatus
  • The response body.

    Declaration

    Swift

    public var body: Data
  • Sends the response back to the client. This will write the Response to the wire in it’s current state.

    Note

    You do not need to call this function directly if using one of the write() functions to populate the response body.

    Declaration

    Swift

    public func send()
  • Writes a text string to the response body and sends it.

    Note

    This function will send() the response.

    Declaration

    Swift

    public func write(_ text: String)

    Parameters

    text

    the response string

  • Encodes the given object as a JSON string, writes it to the response body, and sends it.

    Note

    This function will send() the response.

    Declaration

    Swift

    public func write<T>(json: T) where T : Decodable, T : Encodable

    Parameters

    json

    The Codable to be encoded to JSON