Skip to content

alavers/body-schema

Repository files navigation

NPM version Build Status Dependency Status

JSON schema based validation for express routes. Validate req.body declaratively using JSON schemas. Uses tv4 to create body validation middelware.

Install

$ npm install --save body-schema

Usage

var bodySchema = require('body-schema');

var loginSchema = {
    'type': 'object',
    'properties': {
        'username': {
            'type': 'string'
        },
        'password': {
            'type': 'string'
        }
    },
    'required': ['username', 'password']
};

app.post('/login', bodySchema(loginSchema), login);

License

MIT © Andrew Lavers

TODO:

Shorthand syntax, eg:

app.post('/login', bodySchema(['username', 'password'], login));

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published