April 2020
Intermediate to advanced
716 pages
18h 55m
English
To retrieve the list of open auctions from the database, we will define a backend API that accepts a GET request and queries the Auction collection to return the open auctions that are found in the response. To implement this open auctions API, we will declare a route, as shown here.
mern-marketplace/server/routes/auction.routes.js:
router.route('/api/auctions') .get(auctionCtrl.listOpen)
A GET request that's received at the /api/auctions route will invoke the listOpen controller method, which will query the Auction collection in the database so that it returns all the auctions with ending dates greater than the current date. The listOpen method is defined as follows.
mern-marketplace/server/controllers/auction.controller.js ...
Read now
Unlock full access