schm-express
Express middlewares that leverages schm to parse and validate request query and body.
Install
$ npm install --save schm-express
Usage
const express = const bodyParser = const query body errorHandler = const app = appapp // request GET /?fooapp // request POST / send { foo: 1 }app // request GET / (without required ?foo) will respond with status 400 and error descriptor on response body.app
API
Table of Contents
query
Returns an express middleware that validates and parses querystring based on a given schema.
Parameters
params
Object
Examples
const express = const query = const app = // request /?foo&bar=1&bar=bazapp
body
Returns an express middleware that validates and parses request body based on a given schema.
Parameters
params
Object
Examples
const express = const bodyParser = const body = const app = appapp // send { foo: 1, bar: 'baz' }app
errorHandler
Handles errors from schm-express.
Examples
const express = const query = const app = // request / without querystringapp app // it will respond with 400 and error descriptor in response body
License
MIT © Diego Haz