I think this is actually quite debatable and I've seen a lot of people argue that nested resources are an anti-pattern. I only ever use nested resources myself when the child resource is existentially dependent on the parent.
I think this is actually quite debatable and I've seen a lot of people argue that nested resources are an anti-pattern. I only ever use nested resources myself when the child resource is existentially dependent on the parent.
GET /artist/8/albums
{ albums: [89, 93] }
GET /albums/89
{
album: {
id: 89,
title: 'Blah'
}
} GET /albums?artist=8
GET /albums?artist=8&artist=10
GET /albums?title='Blah'Do:
/artist/8/albums
/albums/9
Don't:
/artist/8/albums/9
Using query filters versus nesting are virtually synonyms. I would say there is a minor semantic distinction in that the first one is a definite relationship, and the second one is a possible relationship. That is, "get the albums for artist 8" versus "get the albums searching for artist 8". The search could include other parameters as well, making it not as definite.
/artist/8/albums
/albums?artist=8
/artist/{artist}/albums
/albums?artist={artist}
AlbumsController#index(artist)