...
/Adding Routes to Get a Single Movie and its Ratings
Adding Routes to Get a Single Movie and its Ratings
Let's learn how to create routes so we can access resources in the database.
In this lesson, we’ll add two more routes—a route to get a specific movie (with its reviews) and a route to get the ratings of all the movies in the database.
MOVIEREVIEWS_DB_URI=mongodb+srv://Cluster09422:XVNEenFBU3N8@cluster09422.yqome88.mongodb.net/sample_mflix?retryWrites=true&w=majority MOVIEREVIEWS_NS=sample_mflix PORT=3000
The initial files we will build on
In the movies.route.js
route file, add the two routes shown below:
Press + to interact
router.route('/').get(MoviesController.apiGetMovies)router.route("/id/:id").get(MoviesController.apiGetMovieById)//route to get a specific movierouter.route("/ratings").get(MoviesController.apiGetRatings) // route to get all ratings
Line 2: This route retrieves a specific movie and all reviews associated with that movie.
Line 3: This route returns a list of movie ratings (such as G
, PG
, R
) so that a user can select the ratings from a dropdown menu in the frontend.
Retrieving movies by ID and rating
Next, let’s implement the apiGetMovieById
and apiGetRatings
methods in MoviesController
...