Book Image

Full-Stack React Projects

By : Shama Hoque
Book Image

Full-Stack React Projects

By: Shama Hoque

Overview of this book

The benefits of using a full JavaScript stack for web development are undeniable, especially when robust and widely adopted technologies such as React, Node, and Express and are available. Combining the power of React with industry-tested, server-side technologies, such as Node, Express, and MongoDB, creates a diverse array of possibilities when developing real-world web applications. This book guides you through preparing the development environment for MERN stack-based web development, to creating a basic skeleton application and extending it to build four different web applications. These applications include a social media, an online marketplace, a media streaming, and a web-based game application with virtual reality features. While learning to set up the stack and developing a diverse range of applications with this book, you will grasp the inner workings of the MERN stack, extend its capabilities for complex features, and gain actionable knowledge of how to prepare MERN-based applications to meet the growing demands of real-world web applications.
Table of Contents (19 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Game APIs


The backend in the MERN VR Game will expose a set of CRUD APIs for creating, editing, reading, listing, and deleting games from the database, which can be used in the frontend of the application, including in the React 360 game implementation, with fetch calls.

The create API

A user who is signed in to the application will be able to create new games in the database using the create API.

Route

In the backend, we will add a POST route in game.routes.js, that verifies that the current user is signed in and authorized, and then creates a new game with the game data passed in the request.

mern-vrgame/server/routes/game.routes.js:

router.route('/api/games/by/:userId')
    .post(authCtrl.requireSignin,authCtrl.hasAuthorization, gameCtrl.create)

To process the :userId param and retrieve the associated user from the database, we will utilize the userByID method from the user controller. We will also add the following to the game routes, so the user is available in the request object as profile...