restify-api-validation
npm install restify-api-validation --save
Contributition and enhancement to repository are most welcome.
Also you can check examples in the test folder how to write validation and see the below details how to use it. Happy coding.
Also let me know if you want enhancement . Tested with latest node.js version 10.15 +
You can use this like this
file: allValidation.js
'use strict';var Joi = ; var validate = login : options: flatten: true body: email: Joi password: Joi register : options: flatten: true body: email: Joi password: Joi ;moduleexportsvalidate =validate;
file: app.js
'use strict'; const restify = ;var validate = ;var validation = validate;globalhttpErrors = restifyerrors; globalserver = restify;server;server;server;server; server; server; // generates a response function sending back to user the specified req[key] { return { res; };} { res;}server;server;// default errorhandler for express-validationserver; moduleexports = server;
Make sure to use this for error catching , tested in restify 5
server;
For more complex structure like this you can do validation
If you have json structure like this
"email":"himmsharma.99@gmail.com" "password":"12345" "userinfo": "nickname":"himanshu" "nickname":"himm" "complexinfo": "name": "firstname":"ram" "firstname":"shyam"
then you can make validation json in the allValidation.js file like this. info is the object like login and register in allValidation.js file . allValidation.js file is above.
var nickname = Joiobject; var firstname = Joiobject;
While working with header reminder to write in lower case
letter.
info : options: flatten: true contextRequest : true headers: authorization: Joi body: email: Joi userinfo :Joi complexinfo :Joiobject