question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to check which combination of req.body properties has been sent by client?

See original GitHub issue

How can we access req.body in validator?

We have a need to inspect the combination of properties (not their values, but properties) client has sent to an API endpoint. So, we don’t want to validate any particular property value but we need to access req.body in validator and then do validation based on Object.keys(req.body).

Is there an elegant way of doing something like that?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gustavohenkecommented, Aug 22, 2017

I see. Unfortunately the most terrible way I could think of is to really use something like you mentioned:

req.checkBody('foo').containsItAndAlsoOtherParams(req.body, otherParams);

And, just to generate some hype… This is something I could bake into version 4, soon to be released. See #383 for some preview 😉

0reactions
lock[bot]commented, Jun 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

req.body empty on posts - node.js - Stack Overflow
You have to check whether the body-parser middleware is set properly to the type of request(json, urlencoded). If you have set, app.use(bodyParser.json());.
Read more >
How To Use the req Object in Express - DigitalOcean
Express servers receive data from the client side through the req object in three instances: the req.params , req.query , and req.body objects....
Read more >
Express.js req.body Property - GeeksforGeeks
The req.body property contains key-value pairs of data submitted in the request body. By default, it is undefined and is populated when you...
Read more >
API Reference - Express 4.x
As req.body 's shape is based on user-controlled input, all properties and values in this object are untrusted and should be validated before...
Read more >
How to handle request validation in your Express API
You can use Ajv directly, however for an Express based API it's nice to be able to use middleware to validate request data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found