April 2020
Intermediate to advanced
716 pages
18h 55m
English
To implement the read media API in the backend, we will start by adding a GET route that queries the Media collection with an ID and returns the media document in the response. The route is declared as follows.
mern-mediastream/server/routes/media.routes.js:
router.route('/api/media/:mediaId') .get( mediaCtrl.incrementViews, mediaCtrl.read)
The mediaId in the request URL will cause the mediaByID controller method to execute and attach the retrieved media document to the request object so that it can be accessed in the next method.
A GET request to this API will execute the incrementViews controller method next, which will find the matching media record and increment the views value by 1, before saving the updated record ...
Read now
Unlock full access