I found that my HTTP delete request runs perfectly when I test it in Postman. However, when I try to test it in the browser, I receive a ‘Cannot GET /account/delete/Julieth’ error. I managed to resolve it by changing the method to GET, which works in both environments. Still, I’m curious why the browser doesn’t recognize the DELETE method. Are there any constraints that the browser has against the DELETE method?
my code:
//deletes the specified resource with GET METHOD.
app.get("/account/delete/:name", function(req,res){
console.log(users);
let filteredArray = users.filter( user => user.name !== req.params.name);
users = filteredArray;
res.send(users);
});
//deletes the specified resource WITH DELETE METHOD. Doesn't work in browser
app.delete("/account/delete/:name", function(req,res){
console.log(users);
let filteredArray = users.filter( user => user.name !== req.params.name);
users = filteredArray;
res.sendStatus(204);
});
I fixed it by changing the method to GET. Also, I make sure I have configured my server to allow requests for cross origin requests. However, do you have any ideas on how to solve the problem without having to change delete to GET so that the browser reads it correctly?
Julieth Bautista is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.