Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fatmatto/express-ajv
Express middleware that helps validating user input with AJV library
https://github.com/fatmatto/express-ajv
ajv api express express-ajv json-schema middleware nodejs validation
Last synced: 1 day ago
JSON representation
Express middleware that helps validating user input with AJV library
- Host: GitHub
- URL: https://github.com/fatmatto/express-ajv
- Owner: fatmatto
- License: mit
- Created: 2018-03-30T07:01:27.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-17T07:15:45.000Z (7 months ago)
- Last Synced: 2025-01-15T14:06:04.327Z (12 days ago)
- Topics: ajv, api, express, express-ajv, json-schema, middleware, nodejs, validation
- Language: JavaScript
- Homepage:
- Size: 224 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/fatmatto/express-ajv.svg?branch=master)](https://travis-ci.org/fatmatto/express-ajv)
# express-ajv
Express middleware that helps validating user input## What
A simple middleware for your expressjs routes that accepts JSON schemas and uses AJV under the hood to validate request payload (querystring, body, headers and params)## Why
* Express validator is good for websites imho, not complex apis
* JSON schema is good and can model anything in your project, this is good for orgs where you have multiple services
* AJV is fast and it just works## How?
`npm i express-ajv-middleware````javascript
const { validateRoute } = require('express-ajv-middleware')// setup your express app
const validatePostFoo = validateRoute({
body: {
type: 'object',
properties: {
'bar': { type: 'integer' },
'baz': { type: 'string' }
},
required: ['bar']
}
})app.post('/foo', validatePostFoo, (req,res,next) => {
// Do your thing here
})
```