我有一个 JSON 文件文件夹,我想用它来创建一个简单的 API。
这是我的文件夹结构的简化版本:
/clients.json
/clients/1/client.json
/clients/2/client.json
...
我的/clients.json
文件如下所示:
[
{
"id": 1,
"name": "Jon Parker"
},
{
"id": 2,
"name": "Gareth Edwards"
},
...
]
我的/clients/1/client.json
文件如下所示:
[
{
"date": "2014-09-12",
"score": 40,
...
},
{
"date": "2015-02-27",
"score": 75,
...
},
{
"date": "2015-05-10",
"score": 75,
...
},
{
"date": "2016-08-27",
"score": 60,
...
}
]
来自的 idclients.json
与关联详细信息所在的文件夹相关。
我在客户端文件夹中有很多 JSON 文件,而不是在客户端单独加载这些文件,我想使用 Node.js 创建一个 API,这给了我更大的灵活性,即..
返回客户端名称和 ID 的列表
/clients
返回客户详细信息
/clients/:id/details
最重要的是返回所有客户名称和相关详细信息
/clients/all/details
我确实开始使用json-server,但是它要求你的 JSON 是一个对象而不是一个数组,不幸的是我被这个 JSON 的格式所困扰。
感谢任何帮助!