RESTful API design with associations

I am trying to create an API for two resources, one with users and the other with movies. Both resources have associations - the user will have several films, and the film will have several users. Presumably, I would develop my API something like this:

/api/users/
/api/users/:id
/api/users/:id/movies

/api/movies/
/api/movies/:id
/api/movies/:id/users

But here is the problem: I also use Backbone.js on the client side to get the API data. If I create a collection in

/api/users/:id/movies

then this will work well for GET requests, but the POST and PUT requests would seem to be directed to:

/api/users/:id/movies/:id

But, it would seem, it would be better if he was sent to

/api/movies/:id

instead of this. It's right? How do people usually deal with RestFul associations?

+5
source share
2 answers

, " POST PUT, , , ...". Backbone.js URL-? , , , , REST API. , REST API, , .

, . ( ):

/api/users/:id/movies
+1

, - URL- REST. , URL- API.

URL- :

/api/getMovies/userId:

/api/updateMovieList/userId:

.

.

-2

All Articles