I am trying to execute a function which deletes a post from the local mongodb database . I Have tested the code with postman it is working but in the frontend i am using axios and the id is needed to be passed as a request parameter , but i am getting an error. My code is unable to pass the id parameter , but backend code looks ok.
xhr.js:166 DELETE http://localhost:3000/api/posts/?id=5da802aa8b54d7220f84110e 404 (Not Found)
axios.delete('/api/posts/',{params:{id:'xyz'}})
although i tested in postman by directy inserting the id (http://localhost:5000/api/posts/xyz_id) with delete request, and it worked.
/////backend
delete(req, res, next){
const postId = req.params.id;
Post.findOneAndDelete({ _id:postId })
.then(post => res.status(204).send(post))
.catch(next);
}
//////frontend
const deletePost =()=>{
axios
.delete('/api/posts/', { params:{ id:'5da802aa8b54d7220f84110e'}})
.then(res => console.log('deleted'))
.catch('err', err => console.log(err));
};