Suppose there are resource like
user - users registered
book - books available in the library
favourite books - users favourite books.
What is the RESTful way to construct the URL for favourite books of a user?
I have confusion on hierarchy of resources in URL. How can I form correct URLs?
The following are the URLs that comes into my mind when there is request to find out favourite books of a user.
users/:user_id/favourites/books
users/:user_id/books/favourites
users/:user_id/favourite_books
What is the correct way of constructing the URLs?
I think it's a matter of personal preference.
Is favourites an important part of the user and do you have more favorites like movies
for example? Then I'd go with this one:
1. users/:user_id/favourites/books
Is this primarily a 'property' of a user's books and will there be more options, like for example last_read
? Then I'd go with this one:
2. users/:user_id/books/favourites
Is this primarily a 'property' of a user and will there be more options, like for example age
? Then I'd go with this one:
3. users/:user_id/favourite_books
You might also want to ask this question on Programmers, I think you'll get more replies there.