0.0.4 • Published 7 years ago

express-arbitrate v0.0.4

Weekly downloads
2
License
UNLICENSED
Repository
github
Last release
7 years ago

Express Middleware to Validate Requests

Usage Example

const express = require('express');
const app = express();
const arbitrate = require('./lib/arbitrate.js');
const _ = require('lodash');
const bodyParser = require('body-parser');

app.use(bodyParser.json());

app.post('/',
    arbitrate.validateRequest({
        info: {
            type: arbitrate.type.CustomObject({
                name: {
                    type: arbitrate.type.String,
                    required: true
                },
                age: {
                    type: arbitrate.type.Integer,
                    required: true
                },
                kids: {
                    type: arbitrate.type.ArrayOf(
                        arbitrate.type.ArrayOf(arbitrate.type.Integer)
                    ),
                    required: true
                }
            }),
            location: arbitrate.location.Body,
            required: true
        }
    }),
    (req, res) => {
        return res.status(200).send({message: 'Success!'});
    }
);

app.listen(2525, () => {
    console.log('App listening on port: 2525');
});