ParametersContainer

public struct ParametersContainer

Helper for accessing route parameters from an HTTP request.

let id = try req.parameters.next(Int.self)
  • The ParameterValues that this request collected as it was being routed.

    Declaration

    Swift

    public var values: [ParameterValue] { get }
  • Gets the raw parameter values from the request URI that match a given parameter type slug.

    let ids = request.parameters.rawValues(for: User.self)
    print(ids) // [String]
    

    Declaration

    Swift

    public func rawValues<P>(for paramter: P.Type) -> [String] where P : Parameter
  • Grabs the next parameter from the parameter bag.

    let id = try req.parameters.next(Int.self)
    

    Note

    the parameters must be fetched in the order they appear in the path.

    For example GET /posts/:post_id/comments/:comment_id must be fetched in this order:

    let post = try req.parameters.next(Post.self)
    let comment = try req.parameters.next(Comment.self)
    

    Declaration

    Swift

    public func next<P>() throws -> P
        where P: Parameter, P.ResolvedParameter == P
  • Grabs the next parameter from the parameter bag.

    let id = try req.parameters.next(Int.self)
    

    Note

    the parameters must be fetched in the order they appear in the path.

    For example GET /posts/:post_id/comments/:comment_id must be fetched in this order:

    let post = try req.parameters.next(Post.self)
    let comment = try req.parameters.next(Comment.self)
    

    Declaration

    Swift

    public func next<P>(_ parameter: P.Type) throws -> P.ResolvedParameter
        where P: Parameter