# koa-route-validator

> koa-route middleware that validate request/response for each route using Joi

Latest version **1.0.0** (published 2019-11-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install koa-route-validator
pnpm add koa-route-validator
yarn add koa-route-validator
bun add koa-route-validator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-11-20 |
| First published | 2018-12-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | ramim, zigius |

## Links

- npm: https://www.npmjs.com/package/koa-route-validator
- Repository: https://github.com/ramimoshe/koa-route-validator
- Homepage: https://github.com/ramimoshe/koa-route-validator#readme
- Issues: https://github.com/ramimoshe/koa-route-validator/issues
- npm.io page: https://npm.io/package/koa-route-validator

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [@hapi/joi](https://npm.io/package/@hapi/joi.md) ^16.1.7

## Recent versions

- 1.0.0 (latest) — 2019-11-20
- 0.0.6 — 2019-02-12
- 0.0.5 — 2019-01-02
- 0.0.4 — 2019-01-01
- 0.0.3 — 2018-12-24
- 0.0.2 — 2018-12-23
- 0.0.1 — 2018-12-23

## README

## koa-route-validator
koa-route middleware that validate request/response for each route using Joi

### install
```bash
npm i koa-route-validator
```

### How to use
#### Using koa-route-validator
```js
const RouteValidator = require('koa-route-validator');
const rv = new RouteValidator();
rv.on('warn', console.warn);
rv.create({/* options */}); // returns koa-router middleware
```

#### Example of using koa-route-validator with koa-router
```js
const RouteValidator = require('koa-route-validator');

const koaRouter = new KoaRouter();
const rv = new RouteValidator();
rv.on('warn', console.warn);
koaRouter.get('/:id', rv.create({
    request: {
        params: Joi.object({})
    }
}), async (ctx) => {
    // route handler
});
```

### Options
```json
{
    "request" : {
        "body"       : {},
        "headers"    : {},
        "params"     : {},
        "queryString": {}
    },
    "response":{ 
        "body"   : {},
        "headers": {}
    }
}
```
* request: optional
  * body: optional - Joi schema for body
  * headers: optional - Joi schema for headers
  * params: optional - Joi schema for params
  * queryString: optional - Joi schema for queryString
* response: optional
  * body: optional - Joi schema for body
  * headers: optional - Joi schema for headers
  

License
----

MIT

---
_Source: https://npm.io/package/koa-route-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
