April 2020
Intermediate to advanced
716 pages
18h 55m
English
To be able to retrieve a list of media that's been uploaded by a specific user from the database, we will set up an API with a route that accepts a GET request at '/api/media/by/:userId'. The route will be declared as follows.
mern-mediastream/server/routes/media.routes.js:
router.route('/api/media/by/:userId') .get(mediaCtrl.listByUser)
A GET request to this route will invoke the listByUser method. The listByUser controller method will query the Media collection to find media documents that have postedBy values matching with the userId attached as a parameter in the URL. The listByUser controller method is defined as follows.
mern-mediastream/server/controllers/media.controller.js:
const listByUser = async (req, res) ...
Read now
Unlock full access