2.0.3 • Published 1 year ago

express-ajv-middleware v2.0.3

Weekly downloads
82
License
MIT
Repository
github
Last release
1 year ago

Build Status

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

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
})
2.0.3

1 year ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

4 years ago

1.0.0

6 years ago