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.
- 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.
- 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.
- Node.js >= 20
- MySQL
- npm or yarn
-
Clone the repository:
git clone https://github.com/thehugoalexandre/MovieAPI.git cd movie-api
-
Install dependencies:
npm install
-
Configure the environment:
- Create or use the
.env
file at the root of the project
- Create or use the
-
Database:
- Before starting the server, ensure the database specified in the
.env
file is created. TheTypeOrmModule
is configured withsynchronize: true
, so tables will be automatically created without needing migrations.
- Before starting the server, ensure the database specified in the
-
Run database migrations:
npm run typeorm migration:run
-
Start the server:
npm run start:dev
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.
-
Register User:
- Method:
POST
- Endpoint:
v1/auth/signup
- Body:
{ "name": "Hugo", "email": "[email protected]", "password": "Password@123" }
- Method:
-
Authentication (Login):
- Method:
POST
- Endpoint:
v1/auth/signin
- Body:
{ "email": "[email protected]", "password": "Password@123" }
- Method:
-
Add Movie:
- Method:
POST
- Endpoint:
v1/movies
- Body:
{ "title": "Inception", "description": "A mind-bending thriller", "releaseDate": "2010-07-16", "genres": [1, 2] }
- Method:
You can use the following link to import the Postman collection for testing the API endpoints: Postman Collection
Contributions are welcome! Please open an issue or submit a pull request to suggest improvements or report bugs.
This project is licensed under the MIT License. See the LICENSE file for more details.