【发布时间】:2015-09-18 19:12:16
【问题描述】:
我想知道 json 是否可以部分分页。
例如
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever."
}
}],
"included": [
{
"type": "people",
"id": 42,
"attributes": {
"name": "John"
}
},
{
...annnd 80000 others
}
}
]
}
included 的元素太多(例如 80.000 个)比我们可能需要分页吗?
但是如果它是分页的并且我们继续下一页只有included元素会改变,json仍然会返回data.articles。
这是正确的行为吗?
第一个提案:
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever."
},
"relationships": {
"users": {
"link": "https://website.com/api/v1/articles/1/users.json"
}
}
}]
}
【问题讨论】:
-
如果 data.articles 的大小会很小,这并不重要。如果它足够大,有一个单独的端点来对包含的文章进行分页
-
您的设置是否可以将
included替换为links,添加特定于您请求的数据的people链接,然后简单地对这些结果进行分页?另请参阅json pagination 文档。 -
@emaillenin 文章将是可能的人中唯一的一个元素。 @omnikron 所以
people在一个新的获取中,没有任何关系?
标签: ruby-on-rails json pagination json-api