json 响应可以部分分页吗?

Can a json response can be partially paginate?

我想知道 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 仍然 return 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"
        }
      }
  }]
}

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

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

如果关系数据是部分集合,可以使用pagination links within the relationship object