I'm having issues sending post requests. Whenever I try and send a post request to localhost:5000/api it gives me this error "POST http://localhost:5000/api 404 (Not Found)" but whenever I do a get request it gives me no errors and works perfectly.
const createPost = async () => {
let res = await axios.post("http://localhost:5000/api", {"id" : 4, "name" : "this was posted by code :)"})
console.log(res)
}
useEffect(() => {
axios.get("http://localhost:5000/api").then(res => {
setBackendData(res.data)
}).catch(err => {
console.log(err)
})
}, [])
If you need anymore of my code please tell me.
Your backend has been written specifically without support for post. If you want, you could read this w3schools article on what different http methods exist. In the modern age, it's all semantic so what api endpoints you choose is up to you (post is generally recommended for security reasons though).
If you want your backend to support post, change your code to use app.post instead of app.get.