April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to retrieve the list of published courses from the database, we will implement an API in the backend, by first declaring the route that will take a GET request at '/api/courses/published', as shown in the following code:
mern-classroom/server/routes/course.routes.js:
router.route('/api/courses/published') .get(courseCtrl.listPublished)
A GET request to this route will invoke the listPublished controller method, which initiates a query to the Course collection for courses that have the published attribute's value as true. Then, the resulting courses are returned in the response. The listPublished controller method is defined as follows:
mern-classroom/server/controllers/course.controller.js:
const listPublished ...