Skip to content

Artesonraju/koa-camino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published