QueryContainer

public struct QueryContainer

Helper for encoding and decoding data from an HTTP request query string.

See Request.query for more information.

  • Serializes an Encodable type to this HTTP request query string.

    let flags: Flags ...
    try req.query.encode(flags)
    

    A MediaType.urlEncodedForm encoder will be used.

    Throws

    Any errors making the decoder for this media type or serializing the query string.

    Declaration

    Swift

    public func encode<E>(_ encodable: E) throws where E : Encodable

    Parameters

    encodable

    Encodable type to encode to this HTTP message.

  • Parses a Decodable type from this HTTP request query string.

    let flags = try req.query.decode(Flags.self)
    print(flags) // Flags
    

    A MediaType.urlEncodedForm decoder will be used.

    Throws

    Any errors making the decoder for this media type or parsing the query string.

    Declaration

    Swift

    public func decode<D>(_ decodable: D.Type) throws -> D where D : Decodable

    Parameters

    decodable

    Decodable type to decode from this HTTP message.

    Return Value

    Instance of the Decodable type.

  • Fetches a single Decodable value at the supplied key-path from this HTTP request’s query string.

    Note: This is a non-throwing subscript convenience method for get(_:at:).

    let name: String? = req.query["user", "name"]
    print(name) /// String?
    

    Declaration

    Swift

    public subscript<D>(_ keyPath: BasicKeyRepresentable...) -> D?
        where D: Decodable

    Parameters

    keyPath

    One or more key path components to the desired value.

    Return Value

    Decoded Decodable value.

  • Fetches a single Decodable value at the supplied key-path from this HTTP request’s query string.

    Note: This is a non-throwing subscript convenience method for get(_:at:).

    let name = req.query[String.self, at: "user", "name"]
    print(name) /// String?
    

    Declaration

    Swift

    public subscript<D>(_ type: D.Type, at keyPath: BasicKeyRepresentable...) -> D?
        where D: Decodable

    Parameters

    type

    The Decodable value type to decode.

    keyPath

    One or more key path components to the desired value.

    Return Value

    Decoded Decodable value.

  • Fetches a single Decodable value at the supplied key-path from this HTTP request’s query string.

    Note: This is a non-throwing subscript convenience method for get(_:at:). This is the non-variadic version.

    let name = req.query[String.self, at: "user", "name"]
    print(name) /// String?
    

    Declaration

    Swift

    public subscript<D>(_ type: D.Type, at keyPath: [BasicKeyRepresentable]) -> D?
        where D: Decodable

    Parameters

    type

    The Decodable value type to decode.

    keyPath

    One or more key path components to the desired value.

    Return Value

    Decoded Decodable value.

  • Fetches a single Decodable value at the supplied key-path from this HTTP request’s query string.

    let name = try req.query.get(String.self, at: "user", "name")
    print(name) /// String
    

    Declaration

    Swift

    public func get<D>(_ type: D.Type = D.self, at keyPath: BasicKeyRepresentable...) throws -> D
        where D: Decodable

    Parameters

    type

    The Decodable value type to decode.

    keyPath

    One or more key path components to the desired value.

    Return Value

    Decoded Decodable value.

  • Fetches a single Decodable value at the supplied key-path from this HTTP request’s query string.

    Note: This is the non-variadic version.

    let name = try req.query.get(String.self, at: "user", "name")
    print(name) /// String
    

    Declaration

    Swift

    public func get<D>(_ type: D.Type = D.self, at keyPath: [BasicKeyRepresentable]) throws -> D
        where D: Decodable

    Parameters

    type

    The Decodable value type to decode.

    keyPath

    One or more key path components to the desired value.

    Return Value

    Decoded Decodable value.