@novice1/validator-joi
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

@novice1/validator-joi

joi validator to use with @novice1/routing.

It provides a middleware that can validate the properties params, body, query, headers, cookies and files from the request using joi validation.

Installation

$ npm install @novice1/validator-joi

Example:

const router = require('@novice1/routing')();
const joi = require('joi');
const validatorJoi = require('@novice1/validator-joi');


/**
 * It will validate the  properties "params", "body", "query", "headers", "cookies" and "files"
 * from the request with the route parameters.
 * 
 */
router.setValidators(
  validatorJoi(
    // joi options
    { stripUnknown: true },
    // middleware in case validation fails
    function onerror(err, req, res, next) {
      res.status(400).json(err);
    }
  )
)

router.get({
  name: 'Main app',
  path: '/app',
  parameters: {
    query: {
      version: joi.number()
    }
  }
}, function (req, res) {
  res.json(req.query.version)
})

References

Package Sidebar

Install

npm i @novice1/validator-joi

Weekly Downloads

6

Version

0.1.3

License

MIT

Unpacked Size

15.9 kB

Total Files

8

Last publish

Collaborators

  • demingongo