2.1.0 • Published 8 years ago

restify-json-schema-validation-middleware v2.1.0

Weekly downloads
33
License
MIT
Repository
github
Last release
8 years ago

restify-json-schema-validation-middleware

Middleware to validate incoming requests using json schema and respond with restify error. Inspired by json-schema-validation-middleware. Based on tv4 and tv4-formats.

Usage

Partial request validation

const validator = require( 'restify-json-schema-validation-middleware' )();

const headersSchema = { type: 'object' };
const bodySchema = { type: 'object' };
const querySchema = { type: 'object' };
const paramsSchema = { type: 'object' };
const filesSchema = { type: 'object' };

server.post(
    '/path',
    validator.headers( headersSchema ),
    validator.body( bodySchema ),
    validator.query( querySchema ),
    validator.params( paramsSchema ),
    validator.files( filesSchema ),
    function( req, res, next ) {
        ...
    }
);

Full request validation

const validator = require( 'restify-json-schema-validation-middleware' )();

const schema = {
    type: 'object',
    properties: {
        headers: { type: 'object' },
        body: { type: 'object' },
        query: { type: 'object' },
        params: { type: 'object' },
        files: { type: 'object' }
    },
    required: [ 'headers' ]
};

server.post(
    '/path',
    validator( schema ),
    function( req, res, next ) {
        ...
    }
);

Options

banUnknownProperties: boolean of whether or not to ban unknown properties

const validator = require( 'restify-json-schema-validation-middleware' )( {
    banUnknownProperties: true
} );
2.1.0

8 years ago

2.0.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago