Node ExpressJS | How to pass custom query params validation2019 Community Moderator ElectionHow to validate an email address in JavaScript?How can I get query string values in JavaScript?How do I pass command line arguments to a Node.js program?How to retrieve POST query parameters?ExpressJS How to structure an application?How to get GET (query string) variables in Express.js on Node.js?How to uninstall npm modules in node js?How do I redirect in expressjs while passing some context?Proper way to set response status and JSON content in a REST API made with nodejs and expressHow to pass props to this.props.children
How to get the n-th line after a grepped one?
Writing in a Christian voice
Are dual Irish/British citizens bound by the 90/180 day rule when travelling in the EU after Brexit?
In the 1924 version of The Thief of Bagdad, no character is named, right?
Worshiping one God at a time?
Bash - pair each line of file
When to use snap-off blade knife and when to use trapezoid blade knife?
Does multi-classing into Fighter give you heavy armor proficiency?
How to define limit operations in general topological spaces? Are nets able to do this?
If "dar" means "to give", what does "daros" mean?
Asserting that Atheism and Theism are both faith based positions
Describing a chess game in a novel
Is this an example of a Neapolitan chord?
Violin - Can double stops be played when the strings are not next to each other?
Hausdorff dimension of the boundary of fibres of Lipschitz maps
Variable completely messes up echoed string
Optimising a list searching algorithm
Can a wizard cast a spell during their first turn of combat if they initiated combat by releasing a readied spell?
What is the plural TO / OF something
I got the following comment from a reputed math journal. What does it mean?
Suggestions on how to spend Shaabath (constructively) alone
What are substitutions for coconut in curry?
I seem to dance, I am not a dancer. Who am I?
What can I do if I am asked to learn different programming languages very frequently?
Node ExpressJS | How to pass custom query params validation
2019 Community Moderator ElectionHow to validate an email address in JavaScript?How can I get query string values in JavaScript?How do I pass command line arguments to a Node.js program?How to retrieve POST query parameters?ExpressJS How to structure an application?How to get GET (query string) variables in Express.js on Node.js?How to uninstall npm modules in node js?How do I redirect in expressjs while passing some context?Proper way to set response status and JSON content in a REST API made with nodejs and expressHow to pass props to this.props.children
Learning ExpressJS here.
I have a get route that expects query params i.e.
app.get('/api', (req, res) =>
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
On postman the following http://localhost:5000/api?name=Messi&age=31&club=Barcelona
returns 200 with the res.body as:
"name": "Messi",
"age": "31",
"club": "Barcelona"
Question
How could I write a custom validation where:
- If the requested query param doesn't exist: status 400
- If any of the params are missing i.e (name, age, club) return a response saying that whichever missing param (name, age, and/or age) is required
javascript node.js rest express ecmascript-6
add a comment |
Learning ExpressJS here.
I have a get route that expects query params i.e.
app.get('/api', (req, res) =>
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
On postman the following http://localhost:5000/api?name=Messi&age=31&club=Barcelona
returns 200 with the res.body as:
"name": "Messi",
"age": "31",
"club": "Barcelona"
Question
How could I write a custom validation where:
- If the requested query param doesn't exist: status 400
- If any of the params are missing i.e (name, age, club) return a response saying that whichever missing param (name, age, and/or age) is required
javascript node.js rest express ecmascript-6
add a comment |
Learning ExpressJS here.
I have a get route that expects query params i.e.
app.get('/api', (req, res) =>
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
On postman the following http://localhost:5000/api?name=Messi&age=31&club=Barcelona
returns 200 with the res.body as:
"name": "Messi",
"age": "31",
"club": "Barcelona"
Question
How could I write a custom validation where:
- If the requested query param doesn't exist: status 400
- If any of the params are missing i.e (name, age, club) return a response saying that whichever missing param (name, age, and/or age) is required
javascript node.js rest express ecmascript-6
Learning ExpressJS here.
I have a get route that expects query params i.e.
app.get('/api', (req, res) =>
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
On postman the following http://localhost:5000/api?name=Messi&age=31&club=Barcelona
returns 200 with the res.body as:
"name": "Messi",
"age": "31",
"club": "Barcelona"
Question
How could I write a custom validation where:
- If the requested query param doesn't exist: status 400
- If any of the params are missing i.e (name, age, club) return a response saying that whichever missing param (name, age, and/or age) is required
javascript node.js rest express ecmascript-6
javascript node.js rest express ecmascript-6
asked Mar 7 at 17:06
Null isTrueNull isTrue
326214
326214
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can build an easy validation middleware.
function validateQuery(fields)
return (req, res, next) =>
for(const field of fields)
if(!req.query[field]) // Field isn't present, end request
return res
.status(400)
.send(`$field is missing`);
next(); // All fields are present, proceed
;
app.get('/api', validateQuery(['name', 'age', 'club']), (req, res) =>
// If it reaches here, you can be sure that all the fields are not empty.
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
You can also use a third party module for validating requests.
- Express Validator
Express Superstruct (I'm the author)
1
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
1
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
add a comment |
You need to check value of every params value
If(typeof req.query.name == 'undefined' )
res.status(400).send('name is missing')
Check for every value
1
I recommend usingreturnbeforeres.status....
– Marcos Casagrande
Mar 7 at 17:12
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
add a comment |
The above answers are correct, but as someone who has worked with scalable and maintenable APIs, I'd recommend standardizing the validation process of you API using JSON Schemas to define the expected input, and AJV to validate these schemas.
Example usage:
const Ajv = require('ajv');
const express = require('express');
const app = express();
app.get('/api', (req, res) =>
// define precisely the expected shape of the request
const schema =
type: 'object',
properties:
name: type: 'string' ,
age: type: 'string' ,
club: type: 'string'
,
required: ['name', 'age', 'club']
// validate the request
const ajv = new Ajv();
const valid = ajv.validate(schema, req.query);
if(!valid) res.status(400).send(ajv.errors);
// request is valid. Do whatever
res.send(req.query);
)
app.listen(8080, () => console.log('Server listening on port 8080'));
Response to /api:
[
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params":
"missingProperty": "name"
,
"message": "should have required property 'name'"
]
Response to /api?name=messi&age=10&club=barcelona:
"name": "messi",
"age": "10",
"club": "barcelona"
Yes it takes a little bit more code, but trust me, it's the way to go if you want to prepare your app for complex and scalable API validation.
absolutely great answer! Have you usedJoibefore?
– Null isTrue
Mar 7 at 19:00
1
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
1
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
how could we save the AJV schema validation inside of avalidateInput()helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?
– Null isTrue
Mar 8 at 0:37
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049303%2fnode-expressjs-how-to-pass-custom-query-params-validation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can build an easy validation middleware.
function validateQuery(fields)
return (req, res, next) =>
for(const field of fields)
if(!req.query[field]) // Field isn't present, end request
return res
.status(400)
.send(`$field is missing`);
next(); // All fields are present, proceed
;
app.get('/api', validateQuery(['name', 'age', 'club']), (req, res) =>
// If it reaches here, you can be sure that all the fields are not empty.
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
You can also use a third party module for validating requests.
- Express Validator
Express Superstruct (I'm the author)
1
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
1
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
add a comment |
You can build an easy validation middleware.
function validateQuery(fields)
return (req, res, next) =>
for(const field of fields)
if(!req.query[field]) // Field isn't present, end request
return res
.status(400)
.send(`$field is missing`);
next(); // All fields are present, proceed
;
app.get('/api', validateQuery(['name', 'age', 'club']), (req, res) =>
// If it reaches here, you can be sure that all the fields are not empty.
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
You can also use a third party module for validating requests.
- Express Validator
Express Superstruct (I'm the author)
1
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
1
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
add a comment |
You can build an easy validation middleware.
function validateQuery(fields)
return (req, res, next) =>
for(const field of fields)
if(!req.query[field]) // Field isn't present, end request
return res
.status(400)
.send(`$field is missing`);
next(); // All fields are present, proceed
;
app.get('/api', validateQuery(['name', 'age', 'club']), (req, res) =>
// If it reaches here, you can be sure that all the fields are not empty.
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
You can also use a third party module for validating requests.
- Express Validator
Express Superstruct (I'm the author)
You can build an easy validation middleware.
function validateQuery(fields)
return (req, res, next) =>
for(const field of fields)
if(!req.query[field]) // Field isn't present, end request
return res
.status(400)
.send(`$field is missing`);
next(); // All fields are present, proceed
;
app.get('/api', validateQuery(['name', 'age', 'club']), (req, res) =>
// If it reaches here, you can be sure that all the fields are not empty.
res.send( name: req.query.name, age: req.query.age, club: req.query.club )
)
You can also use a third party module for validating requests.
- Express Validator
Express Superstruct (I'm the author)
answered Mar 7 at 17:16
Marcos CasagrandeMarcos Casagrande
13.6k32843
13.6k32843
1
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
1
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
add a comment |
1
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
1
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
1
1
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
Fantástico. Thank you very much Marcos!
– Null isTrue
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
You're welcome :)
– Marcos Casagrande
Mar 7 at 17:24
1
1
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
I'll be sure to check out your library as well! 📝
– Null isTrue
Mar 7 at 17:26
add a comment |
You need to check value of every params value
If(typeof req.query.name == 'undefined' )
res.status(400).send('name is missing')
Check for every value
1
I recommend usingreturnbeforeres.status....
– Marcos Casagrande
Mar 7 at 17:12
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
add a comment |
You need to check value of every params value
If(typeof req.query.name == 'undefined' )
res.status(400).send('name is missing')
Check for every value
1
I recommend usingreturnbeforeres.status....
– Marcos Casagrande
Mar 7 at 17:12
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
add a comment |
You need to check value of every params value
If(typeof req.query.name == 'undefined' )
res.status(400).send('name is missing')
Check for every value
You need to check value of every params value
If(typeof req.query.name == 'undefined' )
res.status(400).send('name is missing')
Check for every value
answered Mar 7 at 17:12
Muhammad ShareyarMuhammad Shareyar
816
816
1
I recommend usingreturnbeforeres.status....
– Marcos Casagrande
Mar 7 at 17:12
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
add a comment |
1
I recommend usingreturnbeforeres.status....
– Marcos Casagrande
Mar 7 at 17:12
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
1
1
I recommend using
return before res.status....– Marcos Casagrande
Mar 7 at 17:12
I recommend using
return before res.status....– Marcos Casagrande
Mar 7 at 17:12
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
Marcos, cld you show an example. Obrigado!
– Null isTrue
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
@NullisTrue i'm writing an answer, give me a few minutes.
– Marcos Casagrande
Mar 7 at 17:14
add a comment |
The above answers are correct, but as someone who has worked with scalable and maintenable APIs, I'd recommend standardizing the validation process of you API using JSON Schemas to define the expected input, and AJV to validate these schemas.
Example usage:
const Ajv = require('ajv');
const express = require('express');
const app = express();
app.get('/api', (req, res) =>
// define precisely the expected shape of the request
const schema =
type: 'object',
properties:
name: type: 'string' ,
age: type: 'string' ,
club: type: 'string'
,
required: ['name', 'age', 'club']
// validate the request
const ajv = new Ajv();
const valid = ajv.validate(schema, req.query);
if(!valid) res.status(400).send(ajv.errors);
// request is valid. Do whatever
res.send(req.query);
)
app.listen(8080, () => console.log('Server listening on port 8080'));
Response to /api:
[
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params":
"missingProperty": "name"
,
"message": "should have required property 'name'"
]
Response to /api?name=messi&age=10&club=barcelona:
"name": "messi",
"age": "10",
"club": "barcelona"
Yes it takes a little bit more code, but trust me, it's the way to go if you want to prepare your app for complex and scalable API validation.
absolutely great answer! Have you usedJoibefore?
– Null isTrue
Mar 7 at 19:00
1
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
1
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
how could we save the AJV schema validation inside of avalidateInput()helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?
– Null isTrue
Mar 8 at 0:37
|
show 1 more comment
The above answers are correct, but as someone who has worked with scalable and maintenable APIs, I'd recommend standardizing the validation process of you API using JSON Schemas to define the expected input, and AJV to validate these schemas.
Example usage:
const Ajv = require('ajv');
const express = require('express');
const app = express();
app.get('/api', (req, res) =>
// define precisely the expected shape of the request
const schema =
type: 'object',
properties:
name: type: 'string' ,
age: type: 'string' ,
club: type: 'string'
,
required: ['name', 'age', 'club']
// validate the request
const ajv = new Ajv();
const valid = ajv.validate(schema, req.query);
if(!valid) res.status(400).send(ajv.errors);
// request is valid. Do whatever
res.send(req.query);
)
app.listen(8080, () => console.log('Server listening on port 8080'));
Response to /api:
[
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params":
"missingProperty": "name"
,
"message": "should have required property 'name'"
]
Response to /api?name=messi&age=10&club=barcelona:
"name": "messi",
"age": "10",
"club": "barcelona"
Yes it takes a little bit more code, but trust me, it's the way to go if you want to prepare your app for complex and scalable API validation.
absolutely great answer! Have you usedJoibefore?
– Null isTrue
Mar 7 at 19:00
1
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
1
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
how could we save the AJV schema validation inside of avalidateInput()helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?
– Null isTrue
Mar 8 at 0:37
|
show 1 more comment
The above answers are correct, but as someone who has worked with scalable and maintenable APIs, I'd recommend standardizing the validation process of you API using JSON Schemas to define the expected input, and AJV to validate these schemas.
Example usage:
const Ajv = require('ajv');
const express = require('express');
const app = express();
app.get('/api', (req, res) =>
// define precisely the expected shape of the request
const schema =
type: 'object',
properties:
name: type: 'string' ,
age: type: 'string' ,
club: type: 'string'
,
required: ['name', 'age', 'club']
// validate the request
const ajv = new Ajv();
const valid = ajv.validate(schema, req.query);
if(!valid) res.status(400).send(ajv.errors);
// request is valid. Do whatever
res.send(req.query);
)
app.listen(8080, () => console.log('Server listening on port 8080'));
Response to /api:
[
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params":
"missingProperty": "name"
,
"message": "should have required property 'name'"
]
Response to /api?name=messi&age=10&club=barcelona:
"name": "messi",
"age": "10",
"club": "barcelona"
Yes it takes a little bit more code, but trust me, it's the way to go if you want to prepare your app for complex and scalable API validation.
The above answers are correct, but as someone who has worked with scalable and maintenable APIs, I'd recommend standardizing the validation process of you API using JSON Schemas to define the expected input, and AJV to validate these schemas.
Example usage:
const Ajv = require('ajv');
const express = require('express');
const app = express();
app.get('/api', (req, res) =>
// define precisely the expected shape of the request
const schema =
type: 'object',
properties:
name: type: 'string' ,
age: type: 'string' ,
club: type: 'string'
,
required: ['name', 'age', 'club']
// validate the request
const ajv = new Ajv();
const valid = ajv.validate(schema, req.query);
if(!valid) res.status(400).send(ajv.errors);
// request is valid. Do whatever
res.send(req.query);
)
app.listen(8080, () => console.log('Server listening on port 8080'));
Response to /api:
[
"keyword": "required",
"dataPath": "",
"schemaPath": "#/required",
"params":
"missingProperty": "name"
,
"message": "should have required property 'name'"
]
Response to /api?name=messi&age=10&club=barcelona:
"name": "messi",
"age": "10",
"club": "barcelona"
Yes it takes a little bit more code, but trust me, it's the way to go if you want to prepare your app for complex and scalable API validation.
answered Mar 7 at 17:39
Nino FiliuNino Filiu
2,02621227
2,02621227
absolutely great answer! Have you usedJoibefore?
– Null isTrue
Mar 7 at 19:00
1
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
1
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
how could we save the AJV schema validation inside of avalidateInput()helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?
– Null isTrue
Mar 8 at 0:37
|
show 1 more comment
absolutely great answer! Have you usedJoibefore?
– Null isTrue
Mar 7 at 19:00
1
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
1
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
how could we save the AJV schema validation inside of avalidateInput()helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?
– Null isTrue
Mar 8 at 0:37
absolutely great answer! Have you used
Joi before?– Null isTrue
Mar 7 at 19:00
absolutely great answer! Have you used
Joi before?– Null isTrue
Mar 7 at 19:00
1
1
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
Thank you! Yes I did. The default of Joi is that its schemas are defined only in the JS layer. With AJV and other JSON validators, you can define your schemas in JSON files and import them in your scripts, which gives a big plus in terms of maintanibility.
– Nino Filiu
Mar 7 at 19:02
1
1
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
Additionally, Joi has its own way of defining structures, whereas JSON Schemas is a standard that is shared by many libraries and entities. Side effects, more docs and less bugs for JSON-based structure definitions.
– Nino Filiu
Mar 7 at 19:03
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
That makes sense. I'm looking into AJV now.
– Null isTrue
Mar 7 at 19:24
how could we save the AJV schema validation inside of a
validateInput() helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?– Null isTrue
Mar 8 at 0:37
how could we save the AJV schema validation inside of a
validateInput() helper, so that it could be reusable across multiple http verbs requests while aimng for a DRY approach?– Null isTrue
Mar 8 at 0:37
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55049303%2fnode-expressjs-how-to-pass-custom-query-params-validation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown