@salsita/koa-joi-middleware

1.0.3 • Public • Published

@salsita/koa-joi-middleware

NPM version Downloads Licence Dependency Status devDependency Status

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 */ }
);

Readme

Keywords

none

Package Sidebar

Install

npm i @salsita/koa-joi-middleware

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

2.26 kB

Total Files

3

Last publish

Collaborators