Closed GavinJoyce closed 11 years ago
This is what we currently render:
http://restpack-serializer-sample.herokuapp.com/albums.json?includes=artists
{
"albums": [
{
"id": 1,
"title": "Kid A",
"year": 2000,
"artist_id": 1,
"href": "/albums/1.json"
},
{
"id": 2,
"title": "Amnesiac",
"year": 2001,
"artist_id": 1,
"href": "/albums/2.json"
},
{
"id": 3,
"title": "Murder Ballads",
"year": 1996,
"artist_id": 2,
"href": "/albums/3.json"
},
{
"id": 4,
"title": "Curtains",
"year": 2005,
"artist_id": 3,
"href": "/albums/4.json"
}
],
"meta": {
"albums": {
"page": 1,
"page_size": 10,
"count": 4,
"includes": [
"artists"
],
"page_count": 1,
"previous_page": null,
"next_page": null
}
},
"artists": [
{
"id": 1,
"name": "Radiohead",
"website": "http://radiohead.com/",
"href": "/artists/1.json"
},
{
"id": 2,
"name": "Nick Cave & The Bad Seeds",
"website": "http://www.nickcave.com/",
"href": "/artists/2.json"
},
{
"id": 3,
"name": "John Frusciante",
"website": "http://johnfrusciante.com/",
"href": "/artists/3.json"
}
]
}
This is what we would like to render:
http://restpack-serializer-sample.herokuapp.com/albums.json?includes=artists
{
"links": {
"albums.artist": {
"href": "/artists/{albums.artist}.json",
"type": "artists"
},
"albums.songs": {
"href": "/songs.json?album_id={id}",
"type": "songs"
},
"artists.albums": {
"href": "/albums.json?artist_id={id}",
"type": "albums"
},
"artists.songs": {
"href": "/songs.json?artist_id={id}",
"type": "songs"
}
},
"albums": [
{
"id": 1,
"title": "Kid A",
"year": 2000,
"links": {
"artist": 1
},
"href": "/albums/1.json"
},
{
"id": 2,
"title": "Amnesiac",
"year": 2001,
"links": {
"artist": 1
},
"href": "/albums/2.json"
},
{
"id": 3,
"title": "Murder Ballads",
"year": 1996,
"links": {
"artist": 2
},
"href": "/albums/3.json"
},
{
"id": 4,
"title": "Curtains",
"year": 2005,
"links": {
"artist": 3
},
"href": "/albums/4.json"
}
],
"meta": {
"albums": {
"page": 1,
"page_size": 10,
"count": 4,
"includes": [
"artists"
],
"page_count": 1,
"previous_page": null,
"next_page": null
}
},
"artists": [
{
"id": 1,
"name": "Radiohead",
"website": "http://radiohead.com/",
"href": "/artists/1.json"
},
{
"id": 2,
"name": "Nick Cave & The Bad Seeds",
"website": "http://www.nickcave.com/",
"href": "/artists/2.json"
},
{
"id": 3,
"name": "John Frusciante",
"website": "http://johnfrusciante.com/",
"href": "/artists/3.json"
}
]
}
As per http://jsonapi.org/, represent relationships in
links
format: