0.0.3 • Published 5 years ago

@koex/validate v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

validate

NPM version Coverage Status Dependencies Build Status license issues

validate for koa extend.

Install

$ npm install @koex/validate

Usage

// See more in test
import * as bodyParser from 'koa-body';
import onerror from '@zcorky/onerror';
import validate from '@koex/validate';
import * as router from '@koex/router';

import * as Koa from 'koa';
const app = new Koa();

app.use(onerror());
app.use(bodyParse());
app.use(validate());

app.use(router.post('/', (ctx, next) => {
  ctx.validate({
    name: 'string',
    age: 'int',
  });
}, ctx => {
  ctx.body = ctx.request.body;
}));

app.listen(8000, '0.0.0.0', () => {
  console.log('koa server start at port: 8000');
});

Related