An open API service indexing awesome lists of open source software.

https://github.com/emartech/koa-router-param

Middlewares for Koa Router Params
https://github.com/emartech/koa-router-param

Last synced: over 1 year ago
JSON representation

Middlewares for Koa Router Params

Awesome Lists containing this project

README

          

# koa-router-param

> Params Router middleware for [koa-router](https://github.com/alexmingoia/koa-router)

## Installation

Install using [npm](https://www.npmjs.org/):

```sh
npm install koa-router-param
```

## API Reference

* [koa-router-param(params)](#module_koa-router-param)
* .Type
* _static_ [.Number](#exp_module_koa-router-param--Type--Number)


## 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:

```javascript
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:

```javascript
{ paramName: routerParam.Type.Number }
```

## Contributing

Please submit all issues and pull requests to the [emartech/koa-router-param](https://github.com/emartech/koa-router-param) repository!

## Tests

Run tests using `npm test`.

## Support

If you have any problem or suggestion please open an issue [here](https://github.com/emartech/koa-router-param/issues).