- Notifications
You must be signed in to change notification settings - Fork0
segment-boneyard/koa-params
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Add express styleparamssupport tokoa-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-params
Return a cloned version ofroute with http verbs patched and added.param.
When a route contains:param, callfn with its value andnext. Wait for it to yield before continuing with the real route handler - unless you don't yield and the response ends.
You can register multiplefns perparam, just as with express.
fn can be koa middleware too, whenfn only takes one argument,next will be supplied.
MIT
About
Add express style params support to koa
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
