News for hackers. Stuff that matters.
Re:Some REST best practices by shangxiao on Monday November 17, 2014 @10:22AM (#8618549)
> use nested routing for a cleaner design

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.

Re:Some REST best practices by madeofpalk on Monday November 17, 2014 @10:32AM (#8618595)
I think what he's describing, or at least what I do, is when you get all albums belonging to an artist.

    GET /artist/8/albums
        { albums: [89, 93] }
    
    GET /albums/89
        {
            album: {
                id: 89,
                title: 'Blah'
            }
        }
Re:Some REST best practices by hawleyal on Monday November 17, 2014 @11:35AM (#8618916)
Agreed. Nested routing is fine, as long as it doesn't become redundant.

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

Re:Some REST best practices by shangxiao on Monday November 17, 2014 @11:44AM (#8618984)
Chances are you're (well at least with me) going to do filtering anyway so /artist/8/albums becomes redundant ;)
Re:Some REST best practices by hawleyal on Monday November 17, 2014 @12:00PM (#8619062)
I see what you're saying, but it's not redundant, it's just a synonym. By redundant I meant that there are keys that are not necessary.

/artist/{artist}/albums

/albums?artist={artist}

AlbumsController#index(artist)

Re:Some REST best practices by danielnaab on Monday November 17, 2014 @11:18AM (#8618823)
More flexible:

  GET /albums?artist=8
  GET /albums?artist=8&artist=10
  GET /albums?title='Blah'
Re:Some REST best practices by moron4hire on Monday November 17, 2014 @11:13AM (#8618796)
What about collaborations? The nested hierarchy implies a directed tree structure, but the relationships are really a graph. And I've personally found no more insidious of a problem in data design than trying to shoehorn a graph into a directed tree.
Re:Some REST best practices by hawleyal on Monday November 17, 2014 @11:39AM (#8618943)
The relationships in URIs are abstractions anyway. The data is not actually stored at /artist/8/albums or /albums?artist=8. Both are abstractions of whatever underlying system is used to store the relationships.
Re:Some REST best practices by shangxiao on Monday November 17, 2014 @11:03AM (#8618753)
In this case I would either make albums a field of artist, or just leave it off altogether and just filter /albums based on the artist foreign key.