TrieRouter

public final class TrieRouter<Output>

Generic TrieRouter built using the trie tree algorithm.

Use register(...) to register routes into the router. Use route(...) to then fetch a matching route’s output.

See https://en.wikipedia.org/wiki/Trie for more information.

  • All routes registered to this router.

    Register new routes by using the register(...) method.

    Declaration

    Swift

    public private(set) var routes: [Route<Output>]
  • Configured options such as case-sensitivity.

    Declaration

    Swift

    public var options: Set<RouterOption>
  • Create a new TrieRouter.

    Declaration

    Swift

    public init(_ type: Output.Type = Output.self, options: Set<RouterOption> = [])

    Parameters

    options

    Configured options such as case-sensitivity.

  • Registers a new Route to this router.

    let route = Route<Int>(path: [.constant("users"), User.parameter], output: ...)
    let router = TrieRouter<Int>()
    router.register(route: route)
    

    Declaration

    Swift

    public func register(route: Route<Output>)

    Parameters

    route

    Route to register to this router.

  • Routes a path, returning the best-matching output and collecting any dynamic parameters.

    var params = Parameters()
    router.route(path: ["users", "Vapor"], parameters: &params)
    

    Declaration

    Swift

    public func route<C>(path: [C], parameters: inout Parameters) -> Output? where C: RoutableComponent

    Parameters

    path

    Array of RoutableComponent to route against.

    params

    A mutable Parameters to collect dynamic parameters.

    Return Value

    Best-matching output for the supplied path.