April 2020
Intermediate to advanced
716 pages
18h 55m
English
In the frontend, to make a request to this create API, we will set up a fetch method on the client-side to make a POST request to the API route and pass it the multipart form data containing details of the new auction in the body. This fetch method will be defined as follows.
mern-marketplace/client/auction/api-auction.js:
const create = (params, credentials, auction) => { return fetch('/api/auctions/by/'+ params.userId, { method: 'POST', headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + credentials.t }, body: auction }) .then((response) => { return response.json() }).catch((err) => console.log(err))}
The response that's received from the server will be returned to the component calling ...