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.
[ Parent
| on HN ]
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
Chances are you're (well at least with me) going to do filtering anyway so /artist/8/albums becomes redundant ;)
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.
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.