Create product API

In the backend, we will add a route at /api/products/by/:shopId, which accepts a POST request containing product data, to create a new product associated with the shop identified by the :shopId param. The code to handle this request will first check that the current user is the owner of the shop in which the new product will be added, before creating the new product in the database.

This create product API route is declared in the product.routes.js file, and it utilizes the shopByID and isOwner methods from the shop controller to process the :shopId param, and to verify the current user as the shop owner.

mern-marketplace/server/routes/product.routes.js:

router.route('/api/products/by/:shopId') .post(authCtrl.requireSignin, ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.