Reputation: 3510
I'm working on a REST API and I'm wondering what the naming convention should be for an endpoint that returns two different types of objects. In this contrived example, I've got a call to get a movie (by ID), and another to get the actors associated with a particular movie.
this.app.get('/movies/:id', moviesCtrl.getMovie);
this.app.get('/movies/:id/actors', moviesCtrl.getMovieActors);
My question is, what should be the path for a call that returns both the movie and the actors (i.e., the JSON for the movie but also appends an array of the list of actors)?
this.app.get('/movie-actors/:id', moviesCtrl.getMovieWithActors);
Upvotes: 0
Views: 2192
Reputation: 3077
Now I get full picture. So I would go with the next names:
/movies/:id
/actors/movies/:movieId
or movies_with_actors/:movieId
/movies/:id/actors
Or you can combine 1st and 2nd endpoints and create boolean parameter /movies/:id?actors=true
and /movies/:id?actors=false
But it is just a taste preference. The main idea: path should be meaningful. And the main rule is GET /movies - get all
Get /movies/:id - get one
Upvotes: 3