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

Creating a new game

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

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