Add express style params support to koa-route.
varkoa=require('koa');varroute=require('koa-route')varparamify=require('koa-params');route=paramify(route);varparam=route.param;varget=route.get;varapp=koa();// fake dbvarusers={'julian': {name: 'Julian Gruber',fun: true},'badguy': {name: 'Bad Guy',fun: false}};param('user',function*(id,next){varuser=users[id];if(!user)returnthis.status=404;this.user=user;yieldnext;});app.use(get('/',function*(){this.body=Object.keys(users);}));app.use(get('/:user',function*(){this.body=this.user;}));app.listen(3000);$ npm install koa-paramsReturn a cloned version of route with http verbs patched and added .param.
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.
MIT
