Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

The delete shop API

In order to delete a shop from the database, we will implement a delete shop API in the backend, which will accept a DELETE request from the client at /api/shops/:shopId. We will add the DELETE route for this API as shown in the following code, which will allow an authorized seller to delete one of their own shops:

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

router.route('/api/shops/:shopId')    .delete(authCtrl.requireSignin, shopCtrl.isOwner, shopCtrl.remove)

When a DELETE request is received at this route, if the isOwner method confirms that the signed-in user is the owner of the shop, then the remove controller method deletes the shop specified by the shopId in the param. The remove method is defined as follows:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content