javascript - How to perform jsonschemavalidation through http? -


i have defined restservice , trying jsonschema validation paperwork:

var _ = require('underscore'); var validate = require('isvalid-express'); var paperwork=require('paperwork');  module.exports = function (app) {      app.post('/myroute', paperwork({         username: /[a-z0-9]+/,         password: string,         age: number,         interests: [string],         jobs: [{             company: string,             role: string         }]     }, function (req, res) {         // ...     }));   }; 

this request post in postman myroute:

{   username: 'brucewayne',   password: 'iambatman',   age: 36,   interests: ['climbing', 'cqc', 'cosplay'],   jobs: [{     company: 'wayne inc.',     role: 'ceo'   }] } 

however throws error:

typeerror: undefined not function     @ module.exports (c:\heroku\newher\node_codechallenge\node_modules\paperwork\paperwork.js:129:5)     @ module.exports (c:\heroku\newher\node_codechallenge\app\testroutes.js:12:26)     @ object.<anonymous> (c:\heroku\newher\node_codechallenge\test.js:16:31)     @ module._compile (module.js:456:26)     @ object.module._extensions..js (module.js:474:10)     @ module.load (module.js:356:32)     @ function.module._load (module.js:312:12)     @ module.runmain [as _ontimeout] (module.js:497:10)     @ timer.listontimeout [as ontimeout] (timers.js:112:15) 

what best way of doing json schemavalidation http in node.js?

you may consider using json-schema standard rather non-standard schema definition paperwork uses.

there many javascript json schema validators, here benchmark: https://github.com/ebdrup/json-schema-benchmark


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -