Koa router
$ npm install name
var koa = require('koa'),
Camino = require('koa-camino').Camino,
Step = require('koa-camino').Step;
var app = koa();
var router = new Camino();
/* Configure router */
app.use(router.route);
A Step can contain : A segment (of the url path)
var seg = new Step({segment: 'seg'});
A parameter : corresponding to a some aritrary string in the url path
var seg = new Step({parameter: 'param'});
A HTTP method and an action to be processed
var step = new Step({method: 'GET', action: function*(next){}});
A composition of the last three
var step = new Step({segment: 'seg', parameter: 'param', method: 'GET', action: function*(next){}});
If a step contains a segment and a parameter, it corresponds to a path containing the segment first and then the parameter
Link steps to build an arboresence corresponding to the routes :
parentStep.append(step);
Returns the parent step to allow to chain 'append' calls
Configure the router with the step root of the arboresence
router.addStep(users);
'addStep' calls are chainabe
Using a more classical way, without arborescence...
router.addRoute('POST /users/:id/get', function*(next){});
'addRoute' calls are chainabe
MIT