【问题标题】:Json-server depend on uuid instead of idJson-server 依赖于 uuid 而不是 id
【发布时间】:2019-11-22 07:07:07
【问题描述】:

我使用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

【问题讨论】:

标签: javascript node.js json json-server


【解决方案1】:

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

json-server  db.json --id  'uuid'

【讨论】:

    猜你喜欢
    • 2011-11-05
    • 2017-07-13
    • 2019-02-02
    • 2019-10-24
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    相关资源
    最近更新 更多