我刚开始使用json-server并为一件事而苦苦挣扎。我想要嵌套的 URL,例如为了获取用户组织,请求看起来像:
/rest/user/orgs并且将返回用户组织的数组
{
"rest": {
"user": {
"select": {
"org": []
},
"orgs": [{
"id": "5601e1c0-317c-4af8-9731-a1863f677e85",
"name": "DummyOrg"
}],
"logout": {}
}
}
}
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
图书馆不支持这一点。实现此功能的方法是将自定义路由文件添加到服务器,您将在其中映射(或重定向)/rest/user/对/.
db.json
{
"select": {
"org": []
},
"orgs": [{
"id": "5601e1c0-317c-4af8-9731-a1863f677e85",
"name": "DummyOrg"
}],
"logout": {}
}
Run Code Online (Sandbox Code Playgroud)
routes.json
{
"/rest/user/*": "/$1"
}
Run Code Online (Sandbox Code Playgroud)
然后使用运行它json-server db.json --routes routes.json
| 归档时间: |
|
| 查看次数: |
5437 次 |
| 最近记录: |