Tuesday, 16 October 2018

Strange behavior with HTTP verb Delete and Express

Good day all,​I'm new to express, and am following along in the book: Full-Stack Web Development with Vue.js and Node. I'm getting some very unusual behavior with a Delete request in my application. I can get a delete request to work by passing the id via the request body, however, I can't seem to get the id parameter through params. I've attached the two code samples I'm working with.​I'm using params for my get request, it seems to be just with the Delete verb. Any thoughts?​*** DOES WORK **\*​app.delete("/api/users/", (req, res) => {User.remove({_id: req.body.id}, function(error, user){if(error){req.send("There was an error with the operation, validate you selected a correct ID");}res.send({ success : true})})});​*** DOES NOT WORK **\*app.delete("/api/users/:id", (req, res) => {console.log(req.params.id);res.send(req.params.id);});​Kind regards

Submitted October 16, 2018 at 01:04PM by sma92878

No comments:

Post a Comment