koa-params
Add express style params support to koa-route.
Example
var koa = ;var route = var paramify = ; route = ;var param = routeparam;var get = routeget; var app = ; // fake dbvar users = 'julian': name: 'Julian Gruber' fun: true 'badguy': name: 'Bad Guy' fun: false ; ; app; app; app;
Installation
$ npm install koa-params
API
paramify(route)
Return a cloned version of route
with http verbs patched and added .param
.
route.param(param, fn)
When a route contains :param
, call fn
with its value and next
. Wait for it to yield before continuing with the real route handler - unless you don't yield and the response ends.
You can register multiple fns
per param
, just as with express.
fn
can be koa middleware too, when fn
only takes one argument, next
will be supplied.
License
MIT