beachCode
beachCode

Reputation: 3510

REST API naming convention for multiple resources

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

Answers (1)

Mara
Mara

Reputation: 3077

Now I get full picture. So I would go with the next names:

  1. Movies without actors: /movies/:id
  2. Movies with actors: /actors/movies/:movieId or movies_with_actors/:movieId
  3. Only actors: /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

Related Questions