【发布时间】:2022-11-08 02:52:24
【问题描述】:
在我的 routes.json 中定义的一些自定义端点上调用 DELETE 时遇到了几个问题
我有一些看起来像这样的数据 -
{
"apps": [
{
"creation_time": "2018-06-07 15:56:01",
"description": "Test App",
"id": "2",
"name": "Test",
"update_time": "2018-06-07 15:56:01"
},
],
"account_types": [
{
"app": {
"description": "Test app",
"id": "2",
"name": "Test",
"user_id": "337"
},
"creation_time": "2018-06-07 16:00:31",
"description": "Regular Test account type",
"id": "2",
"max": "None",
"name": "BASIC",
"update_time": "2018-06-07 16:00:31"
},
{
"app": {
"description": "Test app",
"id": "2",
"name": "Test",
"user_id": "337"
},
"creation_time": "2018-08-02 13:48:45",
"description": "Premium Test account type",
"id": "8",
"max": "None",
"name": "PREMIUM",
"update_time": "2018-08-02 13:48:45"
}
]
}
这是我的 routes.json
{
"/test/:app_id/accounts/type": "/account_types?app.id=:app_id",
"/test/:app_id/accounts/type/:type_id": "/account_types?app.id=:app_id&id=:type_id"
}
这是输出
\{^_^}/ hi!
Loading mock-data/apps.json
Loading routes.json
Done
Resources
http://localhost:3000/apps
http://localhost:3000/account_types
Other routes
/test/:app_id/accounts/type -> /account_types?app.id=:app_id
/test/:app_id/accounts/type/:type_id -> /account_types?app.id=:app_id&id=:type_id
Home
http://localhost:3000
Type s + enter at any time to create a snapshot of the database
Watching...
GET /account_types?app.id=2&id=2 200 85.703 ms - 334
GET /account_types?app.id=2&id=4 200 81.023 ms - 2
GET /account_types?app.id=2&id=8 200 38.714 ms - 336
DELETE /account_types?app.id=2&id=8 404 26.290 ms - 2
这就是我运行 json-server 的方式
json-server --watch mock-data/apps.json -r routes.json
当我在这两个端点上调用 GET 时,我检索到了正确的信息,但是当我在它们上调用 DELETE 时,我收到状态码 404,是我做错了什么还是这是一个已知问题?
任何帮助,将不胜感激