I'm trying to send a post request to update an existing record while using a json-server mock API.
I can send GET requests to specific ids and POST reqs to generic endpoints to create new records, but POSTs to specific ids returns a 404. How can it be "Not Found" if I can find it just fine with a GET?
All the questions about it on SO/Github seem to be irrelevant -- mostly coding typos that don't apply. This one seems relevant but is as yet unresolved.
Here's my failing request:
await fetch(`http://localhost:8080/profile/1`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
// ...bunch of new data
}),
})
.then((res) => res.json())
.catch((err) => console.log(err));
Successful POST to generic endpoint:
const newProfile = await fetch(`http://localhost:8080/profile`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
// ...bunch of original data
}),
})
.then((res) => res.json())
.catch((err) => console.log(err));
Successful GET to specific endpoint
const profileData = await fetch(
`http://localhost:8080/profile/${match.params.userId}`
)
.then((res) => res.json())
.catch((err) => console.log(err));
question from:
https://stackoverflow.com/questions/65939557/json-server-404-on-post-req-to-route-id 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…