April 2020
Intermediate to advanced
716 pages
18h 55m
English
In the backend, we will add an API with a GET route that queries the Products collection with an ID and returns the product in the response. The route will be declared as shown in the following code:
mern-marketplace/server/routes/product.routes.js:
router.route('/api/products/:productId') .get(productCtrl.read)
The:productId param in the URL invokes the productByID controller method, which retrieves the product from the database and appends it to the request object. The product in the request object is used by the read controller method to respond to the GET request. The read controller method is defined as follows:
mern-marketplace/server/controllers/product.controller.js:
const read = (req, res) => { req.product.image ...Read now
Unlock full access