Router

public final class Router

Router has a RouteCollection. It can resolve a Route in the RouteCollection and generate a URL for it.

  • An instance of RouteCollection.

    Declaration

    Swift

    public var routes: RouteCollection
  • Initializes a new instance with RouteCollection.

    Declaration

    Swift

    public init(routes: RouteCollection = .init())

    Parameters

    routes

    An instance of RouteCollection. Defaults to an empty RouteCollection.

  • Resolves a Routeby HTTP request method and uri.

    Declaration

    Swift

    public func resolveRouteBy(method: Request.Method, uri: String) -> Route?

    Parameters

    method

    An HTTP request method.

    uri

    A uri string.

    Return Value

    A resolved Route or nil.

  • Resolves a Routeby name.

    Declaration

    Swift

    public func resolveRoute(named name: String) -> Route?

    Parameters

    name

    A unique name for Route.

    Return Value

    A resolved Route or nil.

  • Resolves a Routeby name and path’s parameters.

    Declaration

    Swift

    public func resolveRoute(named name: String, parameters: Parameters<String, String>) -> Route?

    Parameters

    name

    A unique name for Route.

    parameters

    A Route‘s path parameters.

    Return Value

    A resolved Route or nil.

  • Generates a URL for Route by name, path’s parameters and query strings.

    Declaration

    Swift

    public func generateURLForRoute(
        named name: String,
        parameters: Parameters<String, String>? = nil,
        query: Parameters<String, String>? = nil
    ) -> URL?

    Parameters

    name

    A unique name for Route.

    parameters

    A Route‘s path parameters. Defaults to nil.

    query

    A dictionary of query strings. Defaults to nil.

    Return Value

    A generated URL or nil.