April 2020
Intermediate to advanced
716 pages
18h 55m
English
In the frontend, to fetch the shops for a specific user using this list by owner API, we will add a fetch method that takes the signed-in user's credentials to make a GET request to the API route with the specific user ID passed in the URL. This fetch method is defined as shown in the following code:
mern-marketplace/client/shop/api-shop.js:
const listByOwner = async (params, credentials, signal) => { try { let response = await fetch('/api/shops/by/'+params.userId, { method: 'GET', signal: signal, headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + credentials.t } }) return response.json() } catch(err){ console.log(err) }}
The shops returned in the response from the server using ...
Read now
Unlock full access