Router

    Create rules for routing requests and then create Responder that will follow these rules.

    Router.swift:46
    final class Router<Context> where Context : RequestContext

    Router requires an implementation of the on(path:method:use) functions but because it also conforms to RouterMethods it is also possible to call the method specific functions get, put, head, post and patch. The route handler closures all return objects conforming to ResponseGenerator. This allows us to support routes which return a multitude of types eg

    router.get("string") { _, _ -> String in
        return "string"
    }
    router.post("status") { _, _ -> HTTPResponse.Status in
        return .ok
    }
    router.data("data") { request, context -> ByteBuffer in
        return ByteBuffer(string: "buffer")
    }

    The default Router setup in Application is the TrieRouter . This uses a trie to partition all the routes for faster access. It also supports wildcards and parameter extraction

    router.get("user/*", use: anyUser)
    router.get("user/:id", use: userWithId)

    Both of these match routes which start with “/user” and the next path segment being anything. The second version extracts the path segment out and adds it to Request.parameters with the key “id”.

    Citizens in Hummingbird

    Conformances

    Type members

    Instance members

    Instance features