<commit_before># joi-router

Easy, rich and fully validated [koa][] routing.

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/koa-joi-router.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-joi-router
[travis-image]: https://img.shields.io/travis/koajs/joi-router.svg?style=flat-square
[travis-url]: https://travis-ci.org/koajs/joi-router
[codecov-image]: https://codecov.io/github/koajs/joi-router/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/koajs/joi-router?branch=master
[david-image]: https://img.shields.io/david/koajs/joi-router.svg?style=flat-square
[david-url]: https://david-dm.org/koajs/joi-router
[download-image]: https://img.shields.io/npm/dm/koa-joi-router.svg?style=flat-square
[download-url]: https://npmjs.org/package/koa-joi-router
[co]: https://github.com/tj/co
[koa]: http://koajs.com
[co-body]: https://github.com/visionmedia/co-body
[await-busboy]: https://github.com/aheckmann/await-busboy
[joi]: https://github.com/hapijs/joi
[@koa/router]: https://github.com/koajs/router
[generate API documentation]: https://github.com/a-s-o/koa-docs
[path-to-regexp]: https://github.com/pillarjs/path-to-regexp

#### Features:

- built in input validation using [joi][]
- built in [output validation](#validating-output) using [joi][]
- built in body parsing using [co-body][] and [await-busboy][]
- built on the great [@koa/router][]
- [exposed route definitions](#routes) for later analysis
- string path support
- [regexp-like path support](#path-regexps)
- [multiple method support](#multiple-methods-support)
- [multiple middleware support](#multiple-middleware-support)
- [continue on error support](#handling-errors)
- [router prefixing support](#prefix)
- [router level middleware support](#use)
- meta data support
- HTTP 405 and 501 support

#### Node compatibility

NodeJS `>= 7.6` is required.

#### Example

```js
const koa = require('koa');
const router = require('koa-joi-router');
const Joi = router.Joi;

const public = router();

public.get('/', async (ctx) => {
  ctx.body = 'hello joi-router!';
});

public.route({
  method: 'post',
  path: '/signup',
  validate: {
    body: {
      name: Joi.string().max(100),
      email: Joi.string().lowercase().email(),
      password: Joi.string().max(100),
      _csrf: Joi.string().token()
    },
    type: 'form',
    output: {
      200: {
        body: {
          userId: Joi.string(),
          name: Joi.string()
        }
      }
    }
  },
  handler: async (ctx) => {
    const user = await createUser(ctx.request.body);
    ctx.status = 201;
    ctx.body = user;
  }
});

const app = new koa();
app.use(public.middleware());
app.listen(3000);
```

## Usage
`koa-joi-router` returns a constructor which you use to define your routes.
The design is such that you construct multiple router instances, one for
each section of your application which you then add as koa middleware.

```js
const koa = require("koa")
const router = require('koa-joi-router');

const pub = router();
const admin = router();
const auth = router();

// add some routes ..
pub.get('/some/path', async () => {});
admin.get('/admin', async () => {});
auth.post('/auth', async () => {});

const app = new koa();
app.use(pub.middleware());
app.use(admin.middleware());
app.use(auth.middleware());<commit_msg>Update koa module upperCase<commit_after># joi-router

Easy, rich and fully validated [koa][] routing.

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/koa-joi-router.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-joi-router
[travis-image]: https://img.shields.io/travis/koajs/joi-router.svg?style=flat-square
[travis-url]: https://travis-ci.org/koajs/joi-router
[codecov-image]: https://codecov.io/github/koajs/joi-router/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/koajs/joi-router?branch=master
[david-image]: https://img.shields.io/david/koajs/joi-router.svg?style=flat-square
[david-url]: https://david-dm.org/koajs/joi-router
[download-image]: https://img.shields.io/npm/dm/koa-joi-router.svg?style=flat-square
[download-url]: https://npmjs.org/package/koa-joi-router
[co]: https://github.com/tj/co
[koa]: http://koajs.com
[co-body]: https://github.com/visionmedia/co-body
[await-busboy]: https://github.com/aheckmann/await-busboy
[joi]: https://github.com/hapijs/joi
[@koa/router]: https://github.com/koajs/router
[generate API documentation]: https://github.com/a-s-o/koa-docs
[path-to-regexp]: https://github.com/pillarjs/path-to-regexp

#### Features:

- built in input validation using [joi][]
- built in [output validation](#validating-output) using [joi][]
- built in body parsing using [co-body][] and [await-busboy][]
- built on the great [@koa/router][]
- [exposed route definitions](#routes) for later analysis
- string path support
- [regexp-like path support](#path-regexps)
- [multiple method support](#multiple-methods-support)
- [multiple middleware support](#multiple-middleware-support)
- [continue on error support](#handling-errors)
- [router prefixing support](#prefix)
- [router level middleware support](#use)
- meta data support
- HTTP 405 and 501 support

#### Node compatibility

NodeJS `>= 7.6` is required.

#### Example

```js
const koa = require('koa');
const router = require('koa-joi-router');
const Joi = router.Joi;

const public = router();

public.get('/', async (ctx) => {
  ctx.body = 'hello joi-router!';
});

public.route({
  method: 'post',
  path: '/signup',
  validate: {
    body: {
      name: Joi.string().max(100),
      email: Joi.string().lowercase().email(),
      password: Joi.string().max(100),
      _csrf: Joi.string().token()
    },
    type: 'form',
    output: {
      200: {
        body: {
          userId: Joi.string(),
          name: Joi.string()
        }
      }
    }
  },
  handler: async (ctx) => {
    const user = await createUser(ctx.request.body);
    ctx.status = 201;
    ctx.body = user;
  }
});

const app = new koa();
app.use(public.middleware());
app.listen(3000);
```

## Usage
`koa-joi-router` returns a constructor which you use to define your routes.
The design is such that you construct multiple router instances, one for
each section of your application which you then add as koa middleware.

```js
const Koa = require("koa")
const router = require('koa-joi-router');

const pub = router();
const admin = router();
const auth = router();

// add some routes ..
pub.get('/some/path', async () => {});
admin.get('/admin', async () => {});
auth.post('/auth', async () => {});

const app = new Koa();
app.use(pub.middleware());
app.use(admin.middleware());
app.use(auth.middleware());
{'fraction_non_alphanumeric': 0.19112627986348124, 'fraction_numerical': 0.006825938566552901, 'mean_word_length': 4.096376811594203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 34, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6754214', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2471, 'n_words': 512}