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

Fetching the create API in the view

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 ...

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