0.0.2 • Published 10 years ago

koa-camino v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

koa-camino

NPM version Build status Test coverage Dependency Status License

Koa router

Installation

$ npm install name

Seting up a router

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);

Configre using steps

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

Configure using routes

Using a more classical way, without arborescence...

router.addRoute('POST /users/:id/get', function*(next){});

'addRoute' calls are chainabe

License

MIT