koa-router-param
v2.0.2
Published
Middleware for casting koa-router params
Downloads
19
Readme
koa-router-param
Params Router middleware for koa-router
Installation
Install using npm:
npm install koa-router-param
API Reference
- koa-router-param(params)
- .Type
- static .Number
- .Type
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.