1.0.0 • Published 5 years ago

koa-route-validator v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

koa-route-validator

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

install

npm i koa-route-validator

How to use

Using koa-route-validator

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

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

{
    "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

1.0.0

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago