April 2020
Intermediate to advanced
716 pages
18h 55m
English
In the backend, we will define an API to retrieve all the shops from the database, so the shops in the marketplace can be listed in the frontend. This API will accept a request from the client to query the shops collection and return the resulting shop documents in the response. First, we will add a route to retrieve all the shops stored in the database when the server receives a GET request at '/api/shops'. This route is declared as shown in the following code:
mern-marketplace/server/routes/shop.routes.js
router.route('/api/shops') .get(shopCtrl.list)
A GET request received at this route will invoke the list controller method, which will query the shops collection in the database to return all the shops. The list method ...