Reputation: 1129
I have a DELETE request which I have tested and works with POSTMAN.
localhost:5000/api/flavour/5e3feb54e896ab7c00437f0a.
I've even tried passing params for the 2nd parameter in axio layer. but it became ( I would get 404 ) localhost:5000/api/flavour/?id=5e3feb54e896ab7c00437f0a.
However, how can I do that on UI side with axio ? I have tried hardcoded the url for testing,but it doesn't work.
This is my axio code. (Currently keep on getting 405)
DeleteFlavour: async (id) => {
console.log(id);
let res = await axios.delete('/api/flavour/{id}');
console.log(res);
return res.data || [];
}
And this is my route
app.delete(`/api/flavour/:id`, async (req, res) => {
console.log(req.params);
const {id} = req.params;
let flavour = await Flavour.findByIdAndDelete(id);
return res.status(202).send({
error: false,
flavour
})
})
Upvotes: 0
Views: 219
Reputation: 17867
I think you have typo resulting in wrong url. You have:
let res = await axios.delete('/api/flavour/{id}');
It should probably be:
let res = await axios.delete('/api/flavour/' + id);
Or
let res = await axios.delete(`/api/flavour/${id}`);
Upvotes: 2