Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kisiwu/novice-validator-joi
Joi validator to use with @novice1/routing.
https://github.com/kisiwu/novice-validator-joi
middleware routing validator
Last synced: about 2 months ago
JSON representation
Joi validator to use with @novice1/routing.
- Host: GitHub
- URL: https://github.com/kisiwu/novice-validator-joi
- Owner: kisiwu
- License: mit
- Created: 2020-04-05T18:10:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-10T16:06:06.000Z (2 months ago)
- Last Synced: 2024-11-02T04:33:01.082Z (about 2 months ago)
- Topics: middleware, routing, validator
- Language: TypeScript
- Homepage:
- Size: 259 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @novice1/validator-joi
[joi](https://www.npmjs.com/package/joi) validator to use with [@novice1/routing](https://www.npmjs.com/package/@novice1/routing).
It provides a middleware that can validate the properties `params`, `body`, `query`, `headers`, `cookies` and `files` from the request using [joi](https://www.npmjs.com/package/joi) validation.
## Installation
```bash
$ npm install @novice1/validator-joi
```Example:
```js
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
- [joi](https://www.npmjs.com/package/joi)
- [@novice1/routing](https://www.npmjs.com/package/@novice1/routing)