<commit_before># node-restify-validation
Validation for REST Services built with [node-restify](https://github.com/mcavage/node-restify) in node.js

[![Build Status](https://travis-ci.org/gchauvet/node-restify-validation.png)](https://travis-ci.org/gchauvet/node-restify-validation)
[![Coverage Status](https://coveralls.io/repos/gchauvet/node-restify-validation/badge.png?branch=master)](https://coveralls.io/r/gchauvet/node-restify-validation?branch=master)
[![Dependency Status](https://gemnasium.com/z0mt3c/node-restify-validation.png)](https://gemnasium.com/z0mt3c/node-restify-validation)

## Requirements
* node-restify-validation requires at least restify 2.6.0 since the validation model is defined in the route-object. (https://github.com/mcavage/node-restify/pull/408)

## Simple request validation with node-restify
Goal of this little project is to have the validation rules / schema as close to the route itself as possible on one hand without messing up the logic with further LOCs on the other hand.

Example:
```javascript
    var server = restify.createServer();
    server.use(restify.queryParser());
    server.use(restifyValidation.validationPlugin( { errorsAsArray: false }));

    server.get({url: '/test/:name', validation: { params: {
        name: { isRequired: true, isIn: ['foo','bar'] }
    }, query : {
        status: { isRequired: true, isIn: ['foo','bar'] },
        email: { isRequired: false, isEmail: true },
        age: { isRequired: true, isNatural: true }
    }}}, function (req, res, next) {
        res.send(req.params);
    });

    server.put({url: '/products/:id/labels/:label', validation: { params: {
        id: { isRequired: true, isNatural: true },
        label: { isRequired: true }
    }, query : {
        status: { isRequired: true, isIn: ['foo','bar'] }
    }, body {
        label: {isRequired: true }
    }}}, function (req, res, next) {
        res.send(req.params);
    });

    server.listen(8001, function () {
        console.log('%s listening at %s', server.name, server.url);
    });
```
## Use
Simply install it through npm

    npm install git://github.com/gchauvet/node-restify-validation.git


## Documentation powered by swagger
On top of the validation schema the [node-restify-swagger](https://github.com/z0mt3c/node-restify-swagger) library should later-on generate the swagger resources to provide a hands-on documentation.

## Demo project
A simple demo project can be cloned from [node-restify-demo](https://github.com/z0mt3c/node-restify-demo).

## Supported validations

```javascript
    isRequired: true | function()
    equalTo: {'fieldName'}
```

Powered by [node-validator](https://github.com/chriso/validator.js).

    contains
    equals
    is
    isAfter
    isAlpha
    isAlphanumeric
    isBefore
    isCreditCard
    isDate
    isDecimal
    isDivisibleBy
    isEmail
    isFloat
    isHexColor
    isHexadecimal
    isIP
    isIPNet
    isIPv4
    isIPv6<commit_msg>Update documentation<commit_after># node-restify-validation
Validation for REST Services built with [node-restify](https://github.com/mcavage/node-restify) in node.js

[![Build Status](https://travis-ci.org/gchauvet/node-restify-validation.png)](https://travis-ci.org/gchauvet/node-restify-validation)
[![Coverage Status](https://coveralls.io/repos/gchauvet/node-restify-validation/badge.png?branch=master)](https://coveralls.io/r/gchauvet/node-restify-validation?branch=master)
[![Dependency Status](https://gemnasium.com/z0mt3c/node-restify-validation.png)](https://gemnasium.com/z0mt3c/node-restify-validation)

## Requirements
* node-restify-validation requires at least restify 2.6.0 since the validation model is defined in the route-object. (https://github.com/mcavage/node-restify/pull/408)

## Simple request validation with node-restify
Goal of this little project is to have the validation rules / schema as close to the route itself as possible on one hand without messing up the logic with further LOCs on the other hand.

Example:
```javascript
    var server = restify.createServer();
    server.use(restify.queryParser());
    server.use(restifyValidation.validationPlugin( { errorsAsArray: false }));

    server.get({url: '/test/:name', validation: { params: {
        name: { isRequired: true, isIn: ['foo','bar'] }
    }, query : {
        status: { isRequired: true, isIn: ['foo','bar'] },
        email: { isRequired: false, isEmail: true },
        age: { isRequired: true, isNatural: true }
    }}}, function (req, res, next) {
        res.send(req.params);
    });

    server.put({url: '/products/:id/labels/:label', validation: { params: {
        id: { isRequired: true, isNatural: true },
        label: { isRequired: true }
    }, query : {
        status: { isRequired: true, isIn: ['foo','bar'] }
    }, body {
        label: {isRequired: true }
    }}}, function (req, res, next) {
        res.send(req.params);
    });

    server.listen(8001, function () {
        console.log('%s listening at %s', server.name, server.url);
    });
```
## Use
Simply install it through npm

    npm install git://github.com/gchauvet/node-restify-validation.git


## Documentation powered by swagger
On top of the validation schema the [node-restify-swagger](https://github.com/z0mt3c/node-restify-swagger) library should later-on generate the swagger resources to provide a hands-on documentation.

## Supported validations

```javascript
    isRequired: true | function()
    equalTo: {'fieldName'}
```

Powered by [node-validator](https://github.com/chriso/validator.js).

    contains
    equals
    is
    isAfter
    isAlpha
    isAlphanumeric
    isBefore
    isCreditCard
    isDate
    isDecimal
    isDivisibleBy
    isEmail
    isFloat
    isHexColor
    isHexadecimal
    isIP
    isIPNet
    isIPv4
    isIPv6
{'fraction_non_alphanumeric': 0.13575987579782647, 'fraction_numerical': 0.006555114714507504, 'mean_word_length': 3.505050505050505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 21, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '846679', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1811, 'n_words': 433}