Route
public struct Route
extension Route: Equatable
extension Route: CustomStringConvertible
A combination of an HTTP request method, path, name, an array of Middleware, and a handler that points to a location where a resource exists.
-
A default path
/.Declaration
Swift
public static let defaultPath: String -
HandlerAsynchronousA typealias for the handler.
Declaration
Swift
public typealias Handler = (Request) async throws -> Encodable -
An HTTP request method.
Declaration
Swift
public var method: Request.Method -
A path to a resource.
Declaration
Swift
public let path: String -
A regular expression pattern generated for the path.
Declaration
Swift
public private(set) var pattern: String { get } -
A unique name for
Route.Declaration
Swift
public var name: String -
A read-only set of parameters extracted from the path.
Declaration
Swift
public var parameters: Set<Parameter> { get } -
An array of registered
Middleware.Declaration
Swift
public var middleware: [Middleware] -
A handler to call.
Declaration
Swift
public var handler: Handler -
Initializes a new instance with the
defaultPath.Declaration
Swift
public init( method: Request.Method, name: String = "", middleware: [Middleware] = .init(), handler: @escaping Handler )Parameters
methodAn HTTP request method.
nameA unique name for
Route. Defaults to an empty string.middlewareAn array of registered
Middleware. Defaults to an empty array.handlerA handler to call.
-
Initializes a new instance or
nil.Warning
It may returnnilif the path is invalid.Declaration
Swift
public init?( method: Request.Method, path: String, name: String = "", middleware: [Middleware] = .init(), handler: @escaping Handler )Parameters
methodAn HTTP request method.
pathA path to a resource.
nameA unique name for
Route. Defaults to an empty string.middlewareAn array of registered
Middleware. Defaults to an empty array.handlerA handler to call.
-
See
Equatable.Declaration
Swift
public static func == (lhs: Route, rhs: Route) -> Bool -
See
CustomStringConvertible.Declaration
Swift
public var description: String { get } -
Gets a parameter value for a parameter name.
Declaration
Swift
public subscript<T>(parameter name: String) -> T? { get }Parameters
parameterA parameter name.
Return Value
A parameter value.
-
Checks if a path is valid or not.
Declaration
Swift
public static func isValid(path: String) -> (Bool, Set<Parameter>)Parameters
pathA path to a resource.
Return Value
If the path is valid, it returns
trueand a set of extracted parameters. Otherwise, it returnsfalseand an emptySet<Parameter>. -
Generates a regular expression pattern for the path with parameters.
Declaration
Swift
public static func generatePattern(for path: String, with parameters: Set<Parameter> = .init()) -> StringParameters
pathA path to a resource.
parametersA set of parameters.
Return Value
A regular expression pattern.
View on GitHub
Install in Dash
Route Structure Reference