Domanda

Suppose there are resource like

  1. user - users registered

  2. book - books available in the library

  3. 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. please help me to 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.

  1. users/:user_id/favourites/books

  2. users/:user_id/books/favourites

  3. users/:user_id/favourite_books

please help me to form correct way of constructing the urls.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top