April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to use the list API in the frontend, we will define a fetch method that can be used by the React components to load this list of courses. The fetch method that is needed in order to retrieve a list of courses by a specific instructor will be defined as follows.
mern-classroom/client/course/api-course.js
const listByInstructor = async (params, credentials, signal) => { try { let response = await fetch('/api/courses/by/'+params.userId, { method: 'GET', signal: signal, headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + credentials.t } }) return response.json() } catch(err) { console.log(err) }}
This listByInstructor method will take the userId value in order to generate the API route ...
Read now
Unlock full access