如何在创建资源时提供要定义的多个资源?

时间:2015-11-16 19:49:06

标签: json api json-api

请参阅此处的示例:http://jsonapi.org/format/#crud-creating

如果我想指定多位摄影师,我会制作数据'属性数组/集合?

示例(来自上面的链接):

POST /photos HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": { "type": "people", "id": "9" }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

这将是一个数组 - 请参阅复合文档的example

"relationships": {
  "photographers": {
    "data": [
      { "type": "photographers", "id": "5" },
      { "type": "photographers", "id": "12" }
    ]
  }

请注意photographers是复数。

如果您要包含任何实际的摄影师记录,他们会在includeddata处于最高级别。