@salsita/koa-joi-middleware
v1.0.3
Published
[![NPM version](https://img.shields.io/npm/v/@salsita/koa-joi-middleware.svg)](https://www.npmjs.com/package/@salsita/koa-joi-middleware) ![Downloads](https://img.shields.io/npm/dm/@salsita/koa-joi-middleware.svg?style=flat) ![Licence](https://img.shields
Downloads
24
Readme
@salsita/koa-joi-middleware
Middleware used on routes to validate input.
Example:
const joi = require("@hapi/joi");
const Router = require("koa-router");
const joiMiddleware = require("@salsita/koa-joi-middleware");
const router = new Router();
const paramsSchema = joi.object().keys({
id: joi.number().integer().positive().required()
}).required();
const bodySchema = joi.object().keys({
name: joi.string().max(1024).required(),
email: joi.string().email().max(1024).required()
}).required();
router.patch(
'/:id',
joiMiddleware([
{ get: ctx => ctx.params, schema: paramsSchema },
{ get: ctx => ctx.request.body, schema: bodySchema },
],
async ctx => { /* perform stuff */ }
);