Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 617 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
express.js - best POST json schema validator

#1
I'm searching for a module to validate POST json requests in my **Express.js** application.

What json schema module do you use in your node.js apps?

I assume node-validator (

[To see links please register here]

) is not an option here because it works only with strings.
Reply

#2
I made [Paperwork](

[To see links please register here]

), which is a very simple solution for JSON validation. You can do things like:

app.post('/my/route', paperwork({
username: /[a-z0-9]+/,
password: String,
age: Number,
interests: [String],
jobs: [{
company: String,
role: String
},
}, function (req, res) {
// ...
});

It will validate:

{
username: 'brucewayne',
password: 'iambatman',
age: 36,
interests: ['Climbing', 'CQC', 'Cosplay'],
jobs: [{
company: 'Wayne Inc.',
role: 'CEO'
}]
}

Or will silently responds a 400 error with information about what's wrong. Check the doc to do more advanced usages.
Reply

#3
I made this - if you are still interested:

[To see links please register here]

Reply

#4
There are a lot of options for those who choose JSON Schema validation rules. Good libs comparison here:

[To see links please register here]




Reply

#5
I recently wrote [express-jsonschema][1]. The main differences with the other validators out there are:

1. You use the standard [json schemas][2] for validation. If you have
written other server side languages you probably have used them
before.
2. It doesn't control how your application responds to invalid
data. It does give you an opportunity to hook in and respond however
you want. In my experience this is something that is nice to
control.

[express-schema-validator][3], [express-validate][4], and
[Paperwork][5] are all great. They each have their own unique syntax for declaring schemas and also control how your app responds to invalid data (i.e. status code and data structure).




[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through