I am trying to pass a parameter to my DELETE request, I tried to do the following:
Use the same way I use in GET (where it works normal).
app.delete('/contatos', function(req, res){
var obj = req.body;
console.log(obj);
});
However in the NodeJS console this .log()
prints only {}
.
I've also tried this way (I found it in SOen ):
app.delete('/contatos',function(req, res){
var obj = req.body.data;
console.log(obj);
});
But the same thing happened. Maybe the DELETE implementation is different from GET and POST and I skipped some step.
I am requesting the API from AngularJS, with the following service:
angular.module("lista").factory("contatosAPI", function($http){
var _saveContato = function(contato){
return $http.post("http://localhost:3412/contatos", contato);
};
var _deleteContato = function(contato){
console.log(contato); //Aqui o objeto está normal
return $http.delete("http://localhost:3412/contatos", contato);
};
return {
saveContato: _saveContato,
deleteContato: _deleteContato
};
});
controller I call the service, like this:
$scope.apagarContatos = function(contato){
contatosAPI.deleteContato(contato);
};