<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/z0mt3c/node-restify-validation.png)](https://travis-ci.org/z0mt3c/node-restify-validation)
[![Coverage Status](https://coveralls.io/repos/z0mt3c/node-restify-validation/badge.png?branch=master)](https://coveralls.io/r/z0mt3c/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( {
        // Shows errors as an array
        errorsAsArray: false,
        // Not exclude incoming variables not specified in validator rules
        forbidUndefinedVariables: false,
        errorHandler: restify.errors.InvalidArgumentError
    }));

    server.get({url: '/test/:name', validation: {
      resources: {
        name: { isRequired: true, isIn: ['foo','bar'] }
      },
      queries : {
        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: {
      resources: {
        id: { isRequired: true, isNatural: true },
        label: { isRequired: true }<commit_msg>Add files to the docs<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/z0mt3c/node-restify-validation.png)](https://travis-ci.org/z0mt3c/node-restify-validation)
[![Coverage Status](https://coveralls.io/repos/z0mt3c/node-restify-validation/badge.png?branch=master)](https://coveralls.io/r/z0mt3c/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( {
        // Shows errors as an array
        errorsAsArray: false,
        // Not exclude incoming variables not specified in validator rules
        forbidUndefinedVariables: false,
        errorHandler: restify.errors.InvalidArgumentError
    }));

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

    // Ensure there is a file uploaded:
    server.post({url: '/test/:name', validation: {
      resources: {
        name: { isRequired: true, isIn: ['foo','bar'] }
      },
      files : {
        myfile: { isRequired: true }
      }
    }}, function (req, res, next) {
        res.send(req.params);
    });

    server.put({url: '/products/:id/labels/:label', validation: {
      resources: {
        id: { isRequired: true, isNatural: true },
        label: { isRequired: true }
{'fraction_non_alphanumeric': 0.13801902110879147, 'fraction_numerical': 0.008350730688935281, 'mean_word_length': 3.368794326241135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 16, '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': '2693091', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1309, 'n_words': 314}