Skip to content

Commit 790b03e

Browse files
committed
Merge branch 'master' of github.com:fotinakis/jsonapi-serializers
2 parents c2e229b + 66c5e0a commit 790b03e

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ Returns a hash:
7777
},
7878
"links": {
7979
"self": "/posts/1"
80-
}
80+
},
81+
"relationships": {}
8182
}
8283
}
8384
```
@@ -102,7 +103,8 @@ Returns:
102103
},
103104
"links": {
104105
"self": "/posts/1"
105-
}
106+
},
107+
"relationships": {}
106108
},
107109
{
108110
"id": "2",
@@ -113,7 +115,8 @@ Returns:
113115
},
114116
"links": {
115117
"self": "/posts/2"
116-
}
118+
},
119+
"relationships": {}
117120
}
118121
]
119122
}
@@ -264,7 +267,7 @@ JSONAPI::Serializer.serialize(post, include: ['author', 'comments', 'comments.us
264267
Returns:
265268

266269
```json
267-
270+
{
268271
"data": {
269272
"id": "1",
270273
"type": "posts",
@@ -273,7 +276,9 @@ Returns:
273276
"content": "Your first post"
274277
},
275278
"links": {
276-
"self": "/posts/1",
279+
"self": "/posts/1"
280+
},
281+
"relationships": {
277282
"author": {
278283
"self": "/posts/1/links/author",
279284
"related": "/posts/1/author",
@@ -303,7 +308,8 @@ Returns:
303308
},
304309
"links": {
305310
"self": "/users/1"
306-
}
311+
},
312+
"relationships": {}
307313
},
308314
{
309315
"id": "1",
@@ -312,14 +318,20 @@ Returns:
312318
"content": "Have no fear, sers, your king is safe."
313319
},
314320
"links": {
315-
"self": "/comments/1",
321+
"self": "/comments/1"
322+
},
323+
"relationships": {
316324
"user": {
317325
"self": "/comments/1/links/user",
318326
"related": "/comments/1/user",
319327
"linkage": {
320328
"type": "users",
321329
"id": "2"
322330
}
331+
},
332+
"post": {
333+
"self": "/comments/1/links/post",
334+
"related": "/comments/1/post"
323335
}
324336
}
325337
},
@@ -331,19 +343,20 @@ Returns:
331343
},
332344
"links": {
333345
"self": "/users/2"
334-
}
346+
},
347+
"relationships": {}
335348
}
336349
]
337350
}
338351
```
339352

340353
Notice a few things:
341-
* The [primary data](http://jsonapi.org/format/#document-structure-top-level) now includes "linkage" information for each relationship that was included.
354+
* The [primary data](http://jsonapi.org/format/#document-structure-top-level) relationships now include "linkage" information for each relationship that was included.
342355
* The related objects themselves are loaded in the top-level `included` member.
343356
* The related objects _also_ include "linkage" information when a deeper relationship is also present in the compound document. This is a very powerful feature of the JSON:API spec, and allows you to deeply link complicated relationships all in the same document and in a single HTTP response. JSONAPI::Serializers automatically includes the correct linkage information for whatever `include` paths you specify. This conforms to this part of the spec:
344357

345-
> Note: Resource linkage in a compound document allows a client to link together all of the included resource objects without having to GET any relationship URLs.
346-
> [JSON:API Resource Relationships](http://jsonapi.org/format/#document-structure-resource-relationships)
358+
> Note: Full linkage ensures that included resources are related to either the primary data (which could be resource objects or resource identifier objects) or to each other.
359+
> [JSON:API Compound Documents](http://jsonapi.org/format/#document-structure-compound-documents)
347360
348361
#### Relationship path handling
349362

0 commit comments

Comments
 (0)