May 2018
Intermediate to advanced
470 pages
13h 54m
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 the API.
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 npm module, which will help stringify the params object into a query string that can be attached to the request route.
Read now
Unlock full access