Sci-Fi-App Documentation

Purpose

The purpose of this project is to build a complete web application (client-side and server-side) built using full-stack JavaScript technologies. The project will demonstrate full-stack JavaScript development, including APIs, web server frameworks, databases, business logic, authentication, data security, and more. The tech stack used is known as the MERN (MongoDB, Express, React, and Node.js).

Current State

The server is set up by using node.js and express. The website can be locally hosted. It is also hosted at https://sci-fi-app.onrender.com/. Several endpoints have been implemented for retrieving movie data, registering users and adding favorite movies. Requests are logged by middleware using morgan. The data base is implemented with MongoDB. New users can now register. Access and manipulation of all data is now restricted using JWT.

Access

In order to access or manipulate data, users have to register via the /users/register endpoint. The user can then log in with the /login endpoint. After logging in, a bearer token (7 days validity) is sent back. The bearer token has to be used to access any endpoint other than the /users/register and /login endpoints. All users can access information about movies. User data can only be changed by the respective user.

APIs

Register new user

Allows new users to register.

Add a body in JSON format with the following keys:

Request body example:


      {"name": "Mike Smith", "Username":"MikeS", "email": "mike@mike.com", "Password":"3nd93l2wiv", "Birthday":"19091991"}
        
POST /users/register

Response example:


      {
          "name": "Mike Smith",
          "Username": "MikeS",
          "email": "mike@mike.com",
          "Password": "HASHED PASSWORD",
          "favoriteMovies": [],
          "Birthday": ISODate('1991-09-19T00:00:00.000Z'),
          "_id": "664306dcf2678d2d0a509b6c",
          "__v": 0
      }
      

Login

Users can log in and generate a bearer token necessary to access and manipulating data. "Password" and "Username" in the request body.

Request body example:


          {"Username":"MikeSmi", "Password":"asdfasdf"}
        
POST /login

Response example:


        {
          "user": {
              "_id": "66596c2d09083966e8357ceb",
              "name": "Mike Smith",
              "Username": "MikeSmi",
              "email": "mike@mike.com",
              "Password": "HASHED PASSWORD",
              "favoriteMovies": [
                  "663a4446f5fc80b9c0e00d8c",
                  "663a4446f5fc80b9c0e00d8f",
                  "663a4446f5fc80b9c0e00d93"
              ],
              "__v": 0
          },
          "token": "TOKEN"
      }
      

Return all movies

Return a list of ALL movies as a JSON file.

GET /movies

Response example (description shortened in example):


 [
        {
        "genre": {
            "name": "Drama",
            "description": "Drama films are ...."
        },
        "director": {
            "name": "Robert Zemeckis",
            "description": "Robert Zemeckis is an ....",
            "birthyear": "1952-05-14T00:00:00.000Z",
            "deathyear": "1970-01-01T00:00:00.000Z"
        },
        "_id": "663a4446f5fc80b9c0e00d8d",
        "title": "Forrest Gump",
        "description": "Forrest Gump is a ....",
        "ranking": 4
        }, 
        {...},
        ...
 ]
      

Return a single entry

Return data (description, genre, director and ranking) about a single movie by title to the user

GET /movies/{title}

Response example for the title "Inception" (descriptions shortened in example):


      {
          _id: ObjectId('663a4446f5fc80b9c0e00d93'),
          title: 'Inception',
          description: 'new description',
          genre: {
            name: 'Science Fiction',
            description: 'Science fiction films are ... .'
          },
          director: {
            name: 'Christopher Nolan',
            description: "Christopher Nolan is a ... .",
            birthyear: ISODate('1970-07-30T00:00:00.000Z'),
            deathyear: ISODate('1970-01-01T00:00:00.000Z')
          },
          ranking: 8
      }
      

Return data about a genre

Return data about a genre (description) by title of the movie in JSON format.

GET /movies/genre/{title}

Response example for the title "Inception":


      {
          "name": "Science Fiction",
          "description": "Science fiction films are works of fiction that explore imaginative and futuristic concepts, often involving advanced technology, space exploration, and speculative ideas about the future. These films push the boundaries of human imagination, inviting audiences to contemplate the possibilities of the unknown."
      }
      

Return data about a director

Return data about a director (bio, birth year, death year) by movie title in JSON format.

GET /movies/director/{title}

Response example for the title "Inception":


      {
          "name": "Christopher Nolan",
          "description": "Christopher Nolan is a British-American film director, screenwriter, and producer. He is known for his innovative storytelling, intricate plots, and visually stunning cinematography. Nolan's films often explore themes of identity, time, and morality, captivating audiences with their complexity and depth.",
          "birthyear": "1970-07-30T00:00:00.000Z",
          "deathyear": "1970-01-01T00:00:00.000Z"
      }
      

Update user name

Allows users to update their username. Add a body in JSON with the following keys:

Request body example:


 {"oldUserName":"MikeS", "newUsername":"MSmith"}
        
PUT /users/newusername

Response example:


      {
          "_id": "664306dcf2678d2d0a509b6c",
          "name": "Mike Smith",
          "Username": "MSmith",
          "email": "mike@mike.com",
          "password": "HASHED PASSWORD",
          "Birthday": ISODate('1991-09-19T00:00:00.000Z'),
          "favoriteMovies": [],
          "__v": 0
      }
    

Update user details

Allows users to update their username, name, email and birthday. It is possible to change one or several details at once. Add a body in JSON with the appropriate keys. Keys not matching the following list will be ignored. Be careful with the Username since the right Username is needed to log in.

Request body example:


 {"Username":"SMith","name":"Sarah Smith", "Birthday": 25011991, "gender":"female"}
        
PUT /users/newdetails

Response example:


      {
        "_id": "66474157674c6e1cc1d8f8b5",
        "name": "Sarah Smith",
        "Username": "SMith",
        "email": "email@email.com",
        "Password": "HASHED PASSWORD",
        "favoriteMovies": [
            "663a4446f5fc80b9c0e00d93"
        ],
        "__v": 0,
        "Birthday": "1970-01-01T06:56:51.991Z"
    }
    

Update Password

Allow existing user to change the password. Add a body in JSON with the following key:

Request body example:


 {"Password": "eicn7ieks83"}
        
PUT /users/delete

Response example:

"Password updated."

Deregister user

Allow existing users to deregister. Add a body in JSON with the following key:

Request body example:


 {"Username": "MSmith"}
        
DELETE /users/delete

Response example:

"User MSmith deleted."

Add movie to favorites

Allows users to add a movie to their list of favorites. Add a body in JSON with the following key:


 {"favoriteMovie":"Inception"}
        
POST /users/favoritemovie

Response example:


        {
          "_id": "66596c2d09083966e8357ceb",
          "name": "Mike Smith",
          "Username": "MikeSmi",
          "email": "mike@mike.com",
          "Password": "HASHED PASSWORD",
          "favoriteMovies": [
              "663a4446f5fc80b9c0e00d8c",
              "663a4446f5fc80b9c0e00d8f",
              "663a4446f5fc80b9c0e00d93"
          ],
          "__v": 0
      }
               

Remove a movie from favorites

Allows users to remove a movie from their list of favorites. Add a body in JSON format with the following key:


 {"favoriteMovie":"Inception"}
        
DELETE /users/favoritemovie

Response example:


        {
          "_id": "66596c2d09083966e8357ceb",
          "name": "Mike Smith",
          "Username": "MikeSmi",
          "email": "mike@mike.com",
          "Password": "HASHED PASSWORD",
          "favoriteMovies": [
              "663a4446f5fc80b9c0e00d8c",
              "663a4446f5fc80b9c0e00d8f"
          ],
          "__v": 0
      }