使用json服务器正确获取删除请求? [英] Proper Fetch call for Delete using json-server?
本文介绍了使用json服务器正确获取删除请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用json-server创建一个假服务器,然后我从中获取内容.GET正常工作,当我添加到JSON时,POST也是如此,但是当我删除任何内容时,我会收到404错误.所形成的url似乎是正确的,并且确实指向我要删除的JSON,但是仍然给我404.任何想法吗?
Im using json-server to create a fake server and Im fetching stuff from it. The GET works correctly, so does the POST when I add to the JSON, however I get a 404 error when i DELETE anything. The formed url seems to be correct, and it does point to the very JSON I want to delete, however it still gives me a 404. Any ideas?
deleteService = () => {
return fetch(
`http://${delete_url}/services?id=${this.props.data.id}&domain=${
this.props.data.domain
}`,
{
method: "DELETE"
}
)
.then(res => res.json());
};
我的JSON示例
{
"services": [
{
"id": "1",
"domain": "Domain1",
"service_name": "Get Users",
"service_version": "1.0.0",
"method": "GET",
"path": "/abc/def",
"protocol": "HTTP/1.1",
"host": "test.com",
"response": "200"
}
}
错误
删除 http://localhost:3100/services?id = 1& domain =Domain1 404(不是找到)
即使URL在我的JSON上正确存在.
Even though the URL correctly exists on my JSON..
推荐答案
尝试使用axios
await axios.delete(`http://localhost:3100/servicess/${this.props.data.id}`)
并在函数中将id作为参数传递
and in the function pass the id as a param
这篇关于使用json服务器正确获取删除请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文