npm.io
1.15.0 • Published 3 years ago

@qiwi/mware-validator

Licence
MIT
Version
1.15.0
Deps
3
Size
9 kB
Vulns
0
Weekly
0
Stars
2

@qiwi/mware-validator

JSON-schema based validator middleware

Install

yarn add @qiwi/mware-validator
npm i @qiwi/mware-validator

Usage

import validator from '@qiwi/mware-validator'
import express from 'express'

const app = express()
const schema = {
  type: 'object',
  properties: {
    params: {
      id: {
        type: 'string',
        pattern: '[abc]^\d{2}',
        required: true
      }
    },
    query: {
      data: {
        type: 'object',
        required: true
      }
    }
  }
}
app.get('/foo/:id', validator({schema}), (req, res) => {
  ...
  res.send({...})
})

app.listen(...)
License

MIT

Keywords