Expose empty object (representing no request body) as a constant
See original GitHub issueI should be able to do something along the lines of …
import bodyParser, {emptyBody} from 'body-parser';
app.use(bodyParser.raw({
type: 'application/json'
}));
app.use((req, res) => {
if (req.body === emptyBody) {
// ...
}
});
Otherwise, unless I am missing something, there is currently no safe way to check if the request body is empty.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Request body is an empty object - node.js - Stack Overflow
My app index file is this: const express = require("express"); const http = require("http"); const { Server } = require("socket.io"); const ...
Read more >JSON:API — Latest Specification (v1.1)
“Resource objects” appear in a JSON:API document to represent resources. ... resource identifier object for non-empty to-one relationships.
Read more >Web API implementation - Best practices for cloud applications
Learn about best practices for implementing a web API and publishing it to make it available to client applications.
Read more >Writing REST Services with RESTEasy Reactive - Quarkus
Accessing the request body. Any method parameter with no annotation will receive the method body., after it has been mapped from its HTTP ......
Read more >Swagger RESTful API Documentation Specification
A resource in Swagger is an entity that has a set of exposed operations. The entity can represent an actual object (pets, users....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right, it is a breaking change, yes. 2.0 can come out at any point. The only reason it hasn’t come is that there was the strong desire to refactor the internals to support the generic parser case, which is very close to being done (finally!).
FWIW you can accurately detect the body with the additional import of the
type-is
module (which is already a dependency of this module) thoughrequire('type-is').hasBody
export. That is the work-around I’m using within my own code base until 2.0.I’m going to at least try and rebase the current 2.0 branch tonight and cut an alpha of it to npm to give it the proper push forward it needs at this point. This is just an aside, I’m not saying this would really help you in particular.
Yea, we could do that. Right now the 2.0 branch is going to just make
req.body = undefined
when there is no body. Is that possibly a solution here?