Skip to content

Commit c0bc63e

Browse files
committed
Merge pull request #480 from ethanresnick/linkage-for-post
Clarify relationship formatting
2 parents dbc6bc3 + 89a6b99 commit c0bc63e

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

format/index.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ then it **MUST** be specified by including its name in the `ext` media type
4848
parameter with the `Content-Type` header. The value of the `ext` media type
4949
parameter **MUST** be formatted as a comma-separated (U+002C COMMA, ",")
5050
list of extension names and **MUST** be limited to a subset of the
51-
extensions supported by the server, which are listed in `supported-ext`
51+
extensions supported by the server, which are listed in `supported-ext`
5252
of every response.
5353

5454
For example: a response that includes the header `Content-Type:
5555
application/vnd.api+json; ext=ext1,ext2; supported-ext=ext1,ext2,ext3`
5656
indicates that the response document is formatted according to the
57-
extensions "ext1" and "ext2". Another example: a request that includes
57+
extensions "ext1" and "ext2". Another example: a request that includes
5858
the header `Content-Type: application/vnd.api+json; ext=ext1,ext2`
5959
indicates that the request document is formatted according to the
6060
extensions "ext1" and "ext2".
@@ -295,11 +295,12 @@ document, it **MUST** include resource linkage to those resource objects.
295295
Resource linkage **MUST** be represented as one of the following:
296296

297297
* `null` for empty to-one relationships.
298-
* an object containing `"type"` and `"id"` members for non-empty to-one
299-
relationships.
298+
* a "linkage object" (defined below) for non-empty to-one relationships.
300299
* an empty array (`[]`) for empty to-many relationships.
301-
* an array of objects each containing `"type"` and `"id"` members for non-empty
302-
to-many relationships.
300+
* an array of linkage objects for non-empty to-many relationships.
301+
302+
A "linkage object" is an object that identifies an individual related resource.
303+
It **MUST** contain `type` and `id` members.
303304

304305
> Note: Resource linkage in a compound document allows a client to link
305306
together all of the included resource objects without having to `GET` any
@@ -903,11 +904,20 @@ Accept: application/vnd.api+json
903904
"data": {
904905
"type": "photos",
905906
"title": "Ember Hamster",
906-
"src": "http://example.com/images/productivity.png"
907+
"src": "http://example.com/images/productivity.png",
908+
"links": {
909+
"photographer": {
910+
"linkage": { "type": "people", "id": "9" }
911+
}
912+
}
907913
}
908914
}
909915
```
910916

917+
If a relationship is provided in the `links` section of the resource object, its
918+
value **MUST** be a link object with a `linkage` member. The value of this key
919+
represents the linkage the new resource is to have.
920+
911921
#### Client-Generated IDs <a href="#crud-creating-client-ids" id="crud-creating-client-ids" class="headerlink"></a>
912922

913923
A server **MAY** accept a client-generated ID along with a request to create
@@ -1066,13 +1076,11 @@ Accept: application/vnd.api+json
10661076
}
10671077
```
10681078

1069-
#### Updating a Resource's To-One Relationships <a href="#crud-updating-resource-to-one-relationships" id="crud-updating-resource-to-one-relationships" class="headerlink"></a>
1070-
1071-
If a to-one relationship is provided in the `links` section of a resource
1072-
object in a `PATCH` request, its value **MUST** be either:
1079+
#### Updating a Resource's Relationships <a href="#crud-updating-resource-relationships" id="crud-updating-resource-relationships" class="headerlink"></a>
10731080

1074-
* an object with `type` and `id` members corresponding to the related resource
1075-
* `null`, to remove the relationship
1081+
If a relationship is provided in the `links` section of a resource object in a
1082+
`PATCH` request, its value **MUST** be a link object with a `linkage` member.
1083+
The relationship's value will be replaced with the value specified in this member.
10761084

10771085
For instance, the following `PATCH` request will update the `title` attribute
10781086
and `author` relationship of an article:
@@ -1088,22 +1096,15 @@ Accept: application/vnd.api+json
10881096
"id": "1",
10891097
"title": "Rails is a Melting Pot",
10901098
"links": {
1091-
"author": { "type": "people", "id": "1" }
1099+
"author": {
1100+
"linkage": { "type": "people", "id": "1" }
1101+
}
10921102
}
10931103
}
10941104
}
10951105
```
10961106

1097-
#### Updating a Resource's To-Many Relationships <a href="#crud-updating-resource-to-many-relationships" id="crud-updating-resource-to-many-relationships" class="headerlink"></a>
1098-
1099-
If a to-many relationship is included in the `links` section of a resource
1100-
object, it **MUST** be either:
1101-
1102-
* an array of objects each containing `type` and `id` members to replace all
1103-
members of the relationship.
1104-
* an empty array (`[]`) to clear the relationship.
1105-
1106-
For instance, the following `PATCH` request performs a complete replacement of
1107+
Likewise, the following `PATCH` request performs a complete replacement of
11071108
the `tags` for an article:
11081109

11091110
```text
@@ -1117,10 +1118,12 @@ Accept: application/vnd.api+json
11171118
"id": "1",
11181119
"title": "Rails is a Melting Pot",
11191120
"links": {
1120-
"tags": [
1121-
{ "type": "tags", "id": "2" },
1122-
{ "type": "tags", "id": "3" }
1123-
]
1121+
"tags": {
1122+
"linkage": [
1123+
{ "type": "tags", "id": "2" },
1124+
{ "type": "tags", "id": "3" }
1125+
]
1126+
}
11241127
}
11251128
}
11261129
}
@@ -1131,9 +1134,9 @@ relationship. In such a case, the server **MUST** reject the entire update,
11311134
and return a `403 Forbidden` response.
11321135

11331136
> Note: Since full replacement may be a very dangerous operation, a server
1134-
may choose to disallow it. A server may reject full replacement if it has
1135-
not provided the client with the full list of associated objects, and does
1136-
not want to allow deletion of records the client has not seen.
1137+
may choose to disallow it. For example, a server may reject full replacement if
1138+
it has not provided the client with the full list of associated objects, and
1139+
does not want to allow deletion of records the client has not seen.
11371140

11381141
#### Responses <a href="#crud-updating-responses" id="crud-updating-responses" class="headerlink"></a>
11391142

@@ -1209,7 +1212,7 @@ described below.
12091212
The `PATCH` request **MUST** include a top-level member named `data` containing
12101213
one of:
12111214

1212-
* an object with `type` and `id` members corresponding to the related resource.
1215+
* a linkage object (defined above) corresponding to the new related resource.
12131216
* `null`, to remove the relationship.
12141217

12151218
For example, the following request updates the author of an article:
@@ -1245,8 +1248,7 @@ A server **MUST** respond to `PATCH`, `POST`, and `DELETE` requests to a
12451248
*to-many relationship URL* as described below.
12461249

12471250
For all request types, the body **MUST** contain a `data` member whose value
1248-
is an object that contains `type` and `id` members, or an array of objects
1249-
that each contain `type` and `id` members.
1251+
is an empty array or an array of linkage objects.
12501252

12511253
If a client makes a `PATCH` request to a *to-many relationship URL*, the
12521254
server **MUST** either completely replace every member of the relationship,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy