1

我想知道 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"
        }
      }
  }]
}
4

1 回答 1

2

要符合 JSON API 规范,您的复合文档必须遵守完整的链接要求。必须通过关系数据识别任何包含的资源。

在您的示例中,您可以通过在关系data下添加成员来实现这一点。users然后,您可以链接到每个包含的人。

如果关系数据是部分集合,您可以在关系对象中使用分页链接

于 2015-07-03T18:49:55.100 回答