I'm using expressjs and the body-parser middleware.
This is how I initiate it:
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
From the client I'm sending a DELETE request and when I try to pick it up from the server side I get an empty object:
app.delete('/', function(req, res) {
console.log(util.inspect(req.body)); //outputs {}
//some more code
});
however when I send it with a POST I get what I need:
app.post('/delete', function(req, res) {
console.log(util.inspect(req.body)); //outputs { mid: 'ffw1aNh2' }
//some more code
});
It is worth noting that I don't change anything on the client side (angularjs) but the method and the url and the firefox network debugger shows the data being sent in both situations.
What am missing here? Why am I getting an empty body object on a delete method?
body-parser
doesn't care about the HTTP method being used AFAIK, and it should work just fine withDELETE
. Does theContent-Type
header of the request look okay? – Nuthouseapplication/json
and when using DELETE it istext/plain
– Flankbody-parser
is only looking for JSON or URL-encoded body data, nottext/plain
. – Nuthouse$http.delete("/mid/" + mid)
)? – Flank