Modular Koa router middleware with Express-style routes and middleware mounting.
npm install kroute --save
Kroute exports a function which can be used to create router instances that work with Koa middleware.
var koa =var kroute =var app =var router =app
A router can be initialized with default handlers based on a resourceful routing object.
Actions are mapped as follows:
GET / -> index GET /new -> new POST / -> create GET /:id -> show GET /:id/edit -> edit PUT /:id -> update DELETE /:id -> destroy
The object can also contain a
use property which is mounted before any routes.
Every router instance can used to attach request handlers.
Omitting the path name will ensure the handler is always executed when the method matches.
Every route method accepts multiple middleware handlers.
Every router provides a
.all method for attaching request handlers to every method.
It accepts a path and multiple middleware like any other method.
Every router comes with the ability to mount middleware and handlers.
var mount =router
As long as the middleware follows the Koa generator pattern, it can be mounted.
Like other methods,
.use also accepts multiple request handlers and an optional path.
Every path can be dynamic and use Express-style parameter notation.
Every match is stored in the params as an object.
The route can also be a regular expression.
Every method returns it's own instance, so routes can be chained together like Express.
Every method accepts an options object as the last argument.