Latest Threat Research:Malicious dYdX Packages Published to npm and PyPI After Maintainer Compromise.Details
Socket
Book a DemoInstallSign in
Socket

koa-params

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-params

Add express style [params](http://expressjs.com/api.html#app.param) support to [koa-route](https://github.com/koajs/route).

Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

koa-params

Add express style params support to koa-route.

Example

var koa = require('koa');
var route = require('koa-route')
var paramify = require('koa-params');

route = paramify(route);
var param = route.param;
var get = route.get;

var app = koa();

// fake db
var users = {
  'julian': { name: 'Julian Gruber', fun: true },
  'badguy': { name: 'Bad Guy', fun: false }
};

param('user', function*(id, next){
  var user = users[id];
  if (!user) return this.status = 404;
  this.user = user;
  yield next;
});

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 of route with http verbs patched and added .param.

route.param(param, fn)

When a route contains :param, call fn with its value and wait for it to yield until the real route handler is called - unless you don't yield and the response ends.

You can register multiple fns per param, just as with express.

License

MIT

FAQs

Package last updated on 22 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts