hi I have a probleme there. I am coding a crud rest api with (mongo atlas,reactjs,nodejs,express) and want to perform some update data but when using axios.put it is not working. Also when I use postman with the backend (router.patch ..) it works the problem is I can't get axios.put in frontend working. Here is the axios.put syntax in front end:
handleUpdate = async(e) => {
try{
const res = await axios.put('http://127.0.0.1:3000/posts/'+e,{
ville: this.state.ville
})
alert(res.data)
console.log(res.data)
}catch(err){
console.log(err)
}
}
and here is the backend part of code of router.patch: //Update a post {ville}
router.patch('/:PostId', async (req,res) => {
try{
const updatedPost = await Post.updateOne({_id : req.params.PostId},
{ $set: {ville: req.query.ville}
});
res.json(updatedPost);
}catch(err){
res.json({message: err});
}
});
can U help please ??