Package Exports
- node-restify-validation
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-restify-validation) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-restify-validation
Validation for REST Services built with node-restify in node.js
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:
var server = restify.createServer();
server.use(restify.queryParser());
server.use(restifyValidation.validationPlugin( { errorsAsArray: false }));
server.get({url: '/test/:name', validation: {
name: { isRequired: true, isIn: ['foo','bar'], scope: 'path' },
status: { isRequired: true, isIn: ['foo','bar'], scope: 'query' },
email: { isRequired: false, isEmail: true, scope: 'query' },
age: { isRequired: true, isInt: true, scope: 'query' }
}}, function (req, res, next) {
res.send(req.params);
});
server.listen(8001, function () {
console.log('%s listening at %s', server.name, server.url);
});Documentation powered by swagger
On top of the validation schema the 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.
Supported validations
Powered by node-validator.
isRequired
contains
equals
is
isAfter
isAlpha
isAlphanumeric
isBefore
isCreditCard
isDate
isDecimal
isDivisibleBy
isEmail
isFloat
isHexColor
isHexadecimal
isIP
isIPNet
isIPv4
isIPv6
isIn
isInt
isLowercase
isNumeric
isUUID
isUUIDv3
isUUIDv4
isUppercase
isUrl
max
min
not
notContains
notIn
notRegex
regexInspiration
node-restify-validation was & is inspired by backbone.validation. In terms of validation node-restify-validation makes use of node-validator.


