restpack_serializer demo

restpack_serializer provides model serialization, paging, side-loading and filtering. It will implement the emerging jsonapi.org specification.

These examples model Artists --> Albums --> Songs

Here are all artists:

/api/v1/artists.json

here are just two:

/api/v1/artists.json?ids=1,2

and here is a single artist resource:

/api/v1/artists/3.json

Let's side-load their albums:

/api/v1/artists.json?ids=1,2&include=albums

Now we'll side-load albums and songs:

/api/v1/artists.json?ids=1,2&include=albums,songs

Notice that as there may be a large number of songs (there are 31 in this case), we're only returning the first page here. The meta.songs.next_href property links to the next page of song data:

/api/v1/songs.json?artist_ids=1,2&page=2

and if we want to include side-loads:

/api/v1/songs.json?artist_ids=1,2&page=2&include=artists,albums

Let's grab two songs by ID

/api/v1/songs.json?ids=1,33

And include related data:

/api/v1/songs.json?ids=1,33&include=albums,artists

We can also filter by foreign key:

/api/v1/albums.json?artist_id=1

Source: