5

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?

2
  • First step in debugging this would be to go to your network tab in the browser console and inspect the request. Did angular send json, or was the parameter added to the url. Commented Sep 16, 2015 at 18:29
  • 1
    @KevinB it looks it does not send the json but I do not understand why, since the same code of http.post works well. Commented Sep 16, 2015 at 18:39

1 Answer 1

4

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}});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.