Skip to content

thehugoalexandre/MovieAPI

Repository files navigation

Movie API - NestJS Backend Project

NestJS TypeScript MySQL

Description

This is a RESTful API project built with NestJS to manage movies and genres. The API allows CRUD operations on movies and genres, as well as performing searches based on titles and genres. Additionally, a JWT-based authentication system has been implemented to secure the endpoints.

Features

  • JWT Authentication: User registration, Sign In (login), and endpoint protection with JWT tokens.
  • Movies CRUD:
    • Add, list, update, and delete movies.
    • Associate genres with movies.
    • Search for movies by title and/or genre.
  • Genres CRUD:
    • Add, list, and delete genres.
  • Pagination: Implemented for movie listings.
  • Logging Middleware: Logs incoming requests, including information about the authenticated user.
  • Swagger Documentation: Complete API documentation with detailed endpoint descriptions.

Technologies Used

  • NestJS: Framework for building scalable Node.js applications.
  • TypeScript: Programming language used for development.
  • MySQL: Relational database used.
  • TypeORM: ORM used for database interactions.
  • JWT (JSON Web Token): Secure token-based authentication.
  • Winston: Logging library for capturing and storing logs.
  • Swagger: Tool for documenting RESTful APIs.

Installation

Prerequisites

  • Node.js >= 20
  • MySQL
  • npm or yarn

Steps

  1. Clone the repository:

    git clone https://github.com/thehugoalexandre/MovieAPI.git
    cd movie-api
  2. Install dependencies:

    npm install
  3. Configure the environment:

    • Create or use the .env file at the root of the project
  4. Database:

    • Before starting the server, ensure the database specified in the .env file is created. The TypeOrmModule is configured with synchronize: true, so tables will be automatically created without needing migrations.
  5. Run database migrations:

    npm run typeorm migration:run
  6. Start the server:

    npm run start:dev

Usage

API Documentation (Swagger)

After starting the server, go to http://localhost:3000/api to view the API documentation generated by Swagger. This documentation provides clear and objective descriptions for each endpoint.

Example Requests

  1. Register User:

    • Method: POST
    • Endpoint: v1/auth/signup
    • Body:
      {
        "name": "Hugo",
        "email": "[email protected]",
        "password": "Password@123"
      }
  2. Authentication (Login):

    • Method: POST
    • Endpoint: v1/auth/signin
    • Body:
      {
        "email": "[email protected]",
        "password": "Password@123"
      }
  3. Add Movie:

    • Method: POST
    • Endpoint: v1/movies
    • Body:
      {
        "title": "Inception",
        "description": "A mind-bending thriller",
        "releaseDate": "2010-07-16",
        "genres": [1, 2]
      }

Postman Collection

You can use the following link to import the Postman collection for testing the API endpoints: Postman Collection

Contribution

Contributions are welcome! Please open an issue or submit a pull request to suggest improvements or report bugs.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published