# restify-json-schema-validation-middleware

> Middleware to validate incoming requests using json schema and respond with restify error

Latest version **2.1.0** (published 2016-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install restify-json-schema-validation-middleware
pnpm add restify-json-schema-validation-middleware
yarn add restify-json-schema-validation-middleware
bun add restify-json-schema-validation-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2016-08-15 |
| First published | 2016-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Canadian Tire Innovations |
| Maintainers | cantireinnovations |
| Keywords | jsonschema, restify, validation |

## Links

- npm: https://www.npmjs.com/package/restify-json-schema-validation-middleware
- Repository: https://github.com/CanTireInnovations/restify-json-schema-validation-middleware
- Homepage: https://github.com/CanTireInnovations/restify-json-schema-validation-middleware#readme
- Issues: https://github.com/CanTireInnovations/restify-json-schema-validation-middleware/issues
- npm.io page: https://npm.io/package/restify-json-schema-validation-middleware

## Dependencies (3)

- [tv4](https://npm.io/package/tv4.md) ^1.2.7
- [lodash](https://npm.io/package/lodash.md) ^4.2.1
- [tv4-formats](https://npm.io/package/tv4-formats.md) ^2.2.0

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2016-08-15
- 2.0.0 — 2016-02-20
- 1.0.2 — 2016-02-09
- 1.0.1 — 2016-02-09
- 1.0.0 — 2016-02-08

## README

# restify-json-schema-validation-middleware

Middleware to validate incoming requests using json schema and respond with [restify](https://github.com/restify/node-restify) error. Inspired by [json-schema-validation-middleware](https://github.com/jwoudenberg/json-schema-validation-middleware). Based on [tv4](https://github.com/geraintluff/tv4) and [tv4-formats](https:////github.com/ikr/tv4-formats).

## Usage

### Partial request validation

```JavaScript
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

```JavaScript
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
 
```JavaScript
const validator = require( 'restify-json-schema-validation-middleware' )( {
    banUnknownProperties: true
} );
```

---
_Source: https://npm.io/package/restify-json-schema-validation-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
