Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful API URI Design

I'm looking for some direction in regards to the URI design for a RESTful API. I'm going to have several nested linked resources and have currently designed my URI's similar to this post: Hierarchical RESTful URL design

The following example isn't what I'm building but I think illustrates my situation well. (Assume that a show can only belong to one network).

/networks [GET,POST]
/networks/{network_id} [GET,PUT]
/networks/{network_id}/shows [GET,POST]
/networks/{network_id}/shows/{show_id} [GET,PUT]
/networks/{network_id}/shows/{show_id}/episodes [GET,POST]
/networks/{network_id}/shows/{show_id}/episodes/{episode_id} [GET,PUT]

My situation will go two more levels further with associations but all the associations are one to many. I'm considering switching it to something similar to this:

/networks [GET,POST]
/networks/{network_id} [GET,PUT]
/networks/{network_id}/shows [GET,POST]

/shows [GET]
/shows/{id} [GET,PUT]
/shows/{id}/episodes [GET,POST]

/episodes [GET]
/episodes/{id} [GET,PUT]

My questions are:

  1. Is the second example a valid REST design?
  2. Should I consider implementing both paths?
like image 610
TimS Avatar asked Oct 23 '12 20:10

TimS


1 Answers

The second example looks fine to me. The URLs are descriptive of the resources and the correct HTTP verbs are being used.

It is perfectly fine to have multiple URLs pointing to the same resource, if that makes sense. But more importantly, make sure the resources contain <link /> elements that connect shows to networks, episodes to shows, etc.

like image 174
Dmitry S. Avatar answered Oct 27 '22 18:10

Dmitry S.