javascript - Json-server 依赖于 uuid 而不是 id

标签 javascript node.js json json-server

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

最佳答案

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

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

关于javascript - Json-server 依赖于 uuid 而不是 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57008239/

相关文章:

c# - 在 Web API 中将包含 JToken 的对象序列化为 XML 时出现循环引用异常

javascript - 为什么 .simulate ("mouseover") 在 Jest/Enzyme 测试中不起作用?

javascript - 如何使部分文档在 Meteor 中不响应

javascript - jQuery 分页插件

javascript - 标准的 JavaScript 调整

javascript - 如何制作发布apk?

jquery - 如何让 jQuery.parseXML 在 node.js 中工作

javascript - 为什么我们不能通过将长度分配为零来清空 Float32Array() 数组,就像其他普通数组一样?在Javascript中

javascript - 如何将 JavaScript 数组发送到 Rest 服务

Python 替换嵌套 JSON 中的 None 值