Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

jwoudenberg/json-schema-validation-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-schema-validation-middleware

NPM version Build status Dependencies

Validate your incoming requests using a json schema. Tested with restify.

Usage

Create your restify server and your json schema. Adding a validation middleware to an endpoint couldn't be simpler:

var validationMW = require('json-schema-validation-middleware');
server.post('/foo', [
    validationMW(schema),
    myRealHandler
]);

You can optionally configure the middleware to use a custom error handler:

validationMW.configure({
    errorHandler: function (error, res, next) {
        //Do whatever you like here, for instance:
        res.send(400);
    }
});

Formats

The middleware uses the tv4-formats library, so the formats defined there are supported.

Accessing tv4

You can access tv4 directly, for instance to add schema definitions or formatters:

var tv4 = require('json-schema-validation-middleware').tv4;

Development

Style

An .editorconfig and .jshintrc enforce a coding style.

Tasks

Gulp is used as a task runner. Install it globally using npm install -g gulp. To see a list of gulp commands, run gulp help.

Git hooks

Upon commiting or pushing, a git hook wil automatically runt code linting or tests.

About

Validate your incoming requests using a json schema.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published