April 2020
Intermediate to advanced
716 pages
18h 55m
English
To utilize this search API in the frontend, we will set up a method that constructs the URL with query parameters and calls a fetch to make a request to the search product API. This fetch method will be defined as follows.
mern-marketplace/client/product/api-product.js:
import queryString from 'query-string'const list = (params) => { const query = queryString.stringify(params) return fetch('/api/products?'+query, { method: 'GET', }).then(response => { return response.json() }).catch((err) => console.log(err))}
In order to construct the query parameters in the correct format, we will use the query-string node module, which will help stringify the params object into a query string that can be attached to the ...