April 2020
Intermediate to advanced
716 pages
18h 55m
English
A user who is signed in to the application will be able to create new games in the database with the create game API endpoint. For the implementation of this API in the backend, we will first declare a POST route at /api/games/by/:userId, as shown in the following code:
mern-vrgame/server/routes/game.routes.js:
router.route('/api/games/by/:userId') .post(authCtrl.requireSignin, gameCtrl.create)
A POST request to this route will process the :userId param, verify that the current user is signed in, and then create a new game with the game data passed in the request.
The game.routes.js file containing this route declaration will be very similar to the user.routes file, and to load these new routes in the Express app, we ...