Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add express style params support to koa

NotificationsYou must be signed in to change notification settings

segment-boneyard/koa-params

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Add express styleparamssupport tokoa-route.

build status

Example

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

Installation

$ npm install koa-params

API

paramify(route)

Return a cloned version ofroute with http verbs patched and added.param.

route.param(param, fn)

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.

License

MIT

About

Add express style params support to koa

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp