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 shops list API

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 ...

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