Trie Koa Router
Trie routing for Koa based on routington, a fork of Koa Trie Router.
Features
OPTIONS
support405 Method Not Allowed
support501 Not Implemented
support
Routes are generally orthogonal, so the order of definition generally doesn't matter. See routington for more details.
Installation
var app = var Router = var router = app router router
API
router.assertImplementsMethod()
Checks if the server implements a particular method and throws a 501
error otherwise.
This is not middleware, so you would have to use it in your own middleware.
app app
app.use(router.dispatcher())
If you do not do app.use(router.dispatcher())
ever,
routing will never work.
router.route(paths)[method](middleware...)
paths
can be a nested stack of string paths:
router
You can then chain [method](middleware...)
calls.
router
router[method](paths, middleware...)
Similar to above, but you define paths
as the first argument:
router
this.params
this.params
will be defined with any matched parameters.
router
Error handling
The middleware throws an error with code
MALFORMEDURL when it encounters
a malformed path. An application can try/catch this upstream, identify the error
by its code, and handle it however the developer chooses in the context of the
application- for example, re-throw as a 404.
Path Definitions
For path definitions, see routington.
Usage
In trie-router
, routes are orthogonal and strict. Unlike regexp routing, there's no wildcard routing and you can't next
to the next matching route.