Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

The published courses API

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content