RouterRequest

public class RouterRequest

Router request.

  • The hostname of the request.

    Declaration

    Swift

    public var hostname: String
  • The port of the request.

    Declaration

    Swift

    public var port: Int
  • The domain name of the request.

    Declaration

    Swift

    public private(set) lazy var domain: String = { [unowned self] in
  • The subdomains string array of request.

    Declaration

    Swift

    public private(set) lazy var subdomains: [String] = { [unowned self] in
  • The HTTP version of the request.

    Declaration

    Swift

    public let httpVersion: HTTPVersion
  • The method of the request.

    Declaration

    Swift

    public let method: RouterMethod
  • The parsed URL.

    Declaration

    Swift

    public private(set) lazy var parsedURL: URLParser = { [unowned self] in
  • The router as a String.

    Declaration

    Swift

    public internal(set) var route: String?
  • The currently matched section of the URL.

    Declaration

    Swift

    public internal(set) var matchedPath = ""
  • The original URL as a string.

    Declaration

    Swift

    public var originalURL: String
  • url

    The URL. This contains just the path and query parameters starting with ‘/’ Use ‘urlURL’ for the full URL

    Declaration

    Swift

    public var url: String
  • The URL from the request as URLComponents URLComponents has a memory leak on linux as of swift 3.0.1. Use ‘urlURL’ instead

    Declaration

    Swift

    public var urlComponents: URLComponents
  • The URL from the request

    Declaration

    Swift

    public var urlURL: URL
  • List of HTTP headers with simple String values.

    Declaration

    Swift

    public let headers: Headers
  • IP address string of server.

    Declaration

    Swift

    public var remoteAddress: String
  • Parsed Cookies, used to do a lazy parsing of the appropriate headers.

    Declaration

    Swift

    public lazy var cookies: [String: HTTPCookie] = { [unowned self] in
  • List of URL parameters.

    Declaration

    Swift

    public internal(set) var parameters: [String:String] = [:]
  • List of query parameters and comma-separated values.

    Declaration

    Swift

    public lazy var queryParameters: [String:String] = { [unowned self] in
  • Query parameters with values as an array.

    Declaration

    Swift

    public lazy var queryParametersMultiValues: [String: [String]] = { [unowned self] in
  • User info. Can be used by middlewares and handlers to store and pass information on to subsequent handlers.

    Declaration

    Swift

    public var userInfo: [String: Any] = [:]
  • Body of the message.

    Declaration

    Swift

    public internal(set) var body: ParsedBody?
  • Convert query parameters into a QueryParam type

    Declaration

    Swift

    public func getQueryParameters<T: QueryParams>(as type: T.Type) -> T?

    Parameters

    type

    The QueryParam type describing the expected query parameters

    Return Value

    The route’s Query parameters as a QueryParam object

  • Read the body of the request as Data.

    Throws

    Socket.Error if an error occurred while reading from a socket.

    Declaration

    Swift

    public func read(into data: inout Data) throws -> Int

    Parameters

    into

    Data object in which the body of the request is returned.

    Return Value

    the number of bytes read.

  • Read the body of the request as a Codable object. It can decode JSON or URLEncoded forms. It chooses the decoder by looking up the Content-Type header. If there is no header it defaults to JSONDecoder.

    Throws

    Socket.Error if an error occurred while reading from a socket.

    Throws

    DecodingError.dataCorrupted if values requested from the payload are corrupted, or if the given data is not valid JSON.

    Throws

    An error if any value throws an error during decoding.

    Declaration

    Swift

    public func read<T: Decodable>(as type: T.Type) throws -> T

    Parameters

    as

    Codable object to which the body of the request will be converted.

    Return Value

    The instantiated Codable object

  • Read the body of the request as String.

    Throws

    Socket.Error if an error occurred while reading from a socket.

    Declaration

    Swift

    public func readString() throws -> String?

    Return Value

    the String with the request body.

  • Check if passed in types are acceptable based on the request’s header field specified in the first parameter.

    Declaration

    Swift

    public func accepts(header: String = "Accept", types: [String]) -> String?

    Parameters

    header

    name of request’s header field to be checked.

    types

    array of content/mime type strings.

    Return Value

    most acceptable type or nil if there are none.

  • Check if passed in types are acceptable based on the request’s header field specified in the first parameter.

    Declaration

    Swift

    public func accepts(header: String = "Accept", types: String...) -> String?

    Parameters

    header

    name of request’s header field to be checked.

    types

    content/mime type strings.

    Return Value

    most acceptable type or nil if there are none.

  • Check if passed in types are acceptable based on the request’s header field specified in the first parameter.

    Declaration

    Swift

    public func accepts(header: String = "Accept", type: String) -> String?

    Parameters

    header

    name of request’s header field to be checked.

    type

    content/mime type string.

    Return Value

    most acceptable type or nil if there are none.