2

我使用json-server ,我使用这样的数据:

{ 
 "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ]
}

我想使用uuid而不是id,如下所示:

{ 
 "posts": [
    { "uuid": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "uuid": 1, "body": "some comment", "postId": 1 }
  ]
}

但问题是 json-server 在搜索时使用 id 作为主键,例如:

endpoint/posts/1
  • id它的工作
  • 使用uuid不起作用

有没有办法让 json-server 依赖uuid而不是id

4

1 回答 1

3

使用 --id resource_id其中资源是资源的名称。在你的情况下:

json-server  db.json --id  'uuid'
于 2019-07-12T14:06:02.490 回答