I have function to call http.delete and pass a parameter flag:
function softDeleteDatasource(datasourceId,flag) {
var url = baseUrl + datasourceId;
return $http.delete(url, {'currentFieldSetFlag':flag});
}
Then I assume I can get the req.body with following code. However, I always get undefined in the console.log. I used exactly same code in http.post and it works fine when passing parameter.
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
router.delete('/:datasourceId', jsonParser, function(req, res) {
console.log(req.body.currentFieldSetFlag);
}
I am confused why the same code can not pass parameter in http.delete? anyone know how to pass it?
The HTTP spec allows for bodies on DELETEs, but some clients do not send them and some proxies/servers will strip/ignore them if present. This ought to work to pass it as a querystring parameter:
return $http.delete(url, {params: {'currentFieldSetFlag':flag}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With