koa-router-param

2.0.2 • Public • Published

koa-router-param

Params Router middleware for koa-router

Installation

Install using npm:

npm install koa-router-param

API Reference

KoaRouterParam(params) ⇒ Generator

Creates a middleware for koa-router route.

Parameters

Param Type Description
params Object An object representing the processable URL params
↳ key String Name of the param in the URL
↳ value Generator A transformer for the param's value

Example

Basic usage:

var Router = require('koa-router');
var routerParam = require('koa-router-param');
 
router
    .get(
        '/users/:userId',
        routerParam({ userId: routerParam.Type.Number }),
        function *(next) {
            console.log(this.params.userId); // => Number(123)
        }
    );

RouterParam.Type.Number ⇒ Generator

Casts the given parameter to Number.

Example

Basic usage:

{ paramName: routerParam.Type.Number }

Contributing

Please submit all issues and pull requests to the emartech/koa-router-param repository!

Tests

Run tests using npm test.

Support

If you have any problem or suggestion please open an issue here.

Readme

Keywords

none

Package Sidebar

Install

npm i koa-router-param

Weekly Downloads

1

Version

2.0.2

License

MIT

Last publish

Collaborators

  • emarsys-deployer
  • adambrunner