gpt4 book ai didi

json-api - 如何创建复合文档?

转载 作者:行者123 更新时间:2023-12-02 18:01:49 25 4
gpt4 key购买 nike

我正在考虑使用 JSONAPI我们的 API 设计标准。该 API 必须能够做的一件事是接受复合文档(多层深)并创建它。根对象拥有所有后代(“对多”关系),服务器此时对此一无所知,因此客户端不可能提供 id。

规范是否支持这一点,或者客户端是否必须按顺序对文档中的每个对象发出 http 请求?

最佳答案

来自 http://jsonapi.org/format/#document-compound-documents

Compound documents require "full linkage", meaning that every included resource MUST be identified by at least one resource identifier object in the same document. These resource identifier objects could either be primary data or represent resource linkage contained within primary or included resources. The only exception to the full linkage requirement is when relationship fields that would otherwise contain linkage data are excluded via sparse fieldsets.

{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"links": {
"self": "http://example.com/articles/1"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
},
"comments": {
"links": {
"self": "http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
}
}],
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"links": {
"self": "http://example.com/people/9"
}
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
},
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
},
"links": {
"self": "http://example.com/comments/12"
}
}]
}

关于json-api - 如何创建复合文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30704498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com