April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to use the create API in the frontend, we will set up a fetch method on the client- side to make a POST request to the create API, by passing the multipart form data, as shown in the following code:
mern-classroom/client/course/api-course.js
const create = async (params, credentials, course) => { try { let response = await fetch('/api/courses/by/'+ params.userId, { method: 'POST', headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + credentials.t }, body: course }) return response.json() } catch(err) { console.log(err) }}
This method will be used in the new course form view to submit the user-entered course details to the backend to create a new course in the database. In the ...