Movies API
A server-side application built with NestJS and TypeScript for managing movies, user favorites, authentication, and API keys.
π Overview
The Movies API is a server-side application built with NestJS and TypeScript. It provides endpoints for managing movies, user favorites, authentication, and API keys. The API is designed with modular architecture, robust validation, and secure authentication mechanisms.
β‘ Features
- π Authentication: Secure login, registration, and token-based authentication.
- π¬ Movies: Fetch popular, trending, top-rated, and upcoming movies from TMDB.
- πΎ Favorites: Manage user-specific favorite movies.
- π API Keys: Generate, validate, and manage API keys for external integrations.
- π Swagger Documentation: Interactive API documentation.
π οΈ Tech Stack
The project is built using the following technologies:
- π TypeScript
- π¦ΈββοΈ NestJS
- ποΈ MongoDB
- π³ Docker
- π Swagger
π API Documentation
π Auth Endpoints
π POST /auth/login
Authenticate a user and return access and refresh tokens.
π₯ Request Body
{
"email": "user@mail.com",
"password": "secure@pass123"
}
π€ Response
{
"user": {
"id": "123",
"email": "user@mail.com",
"name": "User"
},
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
π POST /auth/register
Register a new user.
π₯ Request Body
{
"name": "User",
"email": "user@mail.com",
"password": "secure@pass123"
}
π€ Response
{
"user": {
"id": "123",
"email": "user@mail.com",
"name": "User"
},
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
π POST /auth/refresh
Refresh the access token using a refresh token.
π₯ Request Body
{
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
π€ Response
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
π¬ Movies Endpoints
π GET /movies/popular
Fetch popular movies from TMDB.
- Query Parameters: page (optional): Page number for pagination.
π€ Response
{
"page": 1,
"results": [
{
"id": 550,
"title": "Fight Club",
"overview": "A ticking-time-bomb insomniac...",
"poster_path": "/poster.jpg",
"release_date": "1999-10-15",
"vote_average": 8.4
}
],
"total_results": 1000,
"total_pages": 50
}
π GET /movies/trending
Fetch trending movies.
- Query Parameters: timeWindow (optional): day or week.
π€ Response
{
"page": 1,
"results": [
{
"id": 550,
"title": "Fight Club",
"overview": "A ticking-time-bomb insomniac...",
"poster_path": "/poster.jpg",
"release_date": "1999-10-15",
"vote_average": 8.4
}
],
"total_results": 1000,
"total_pages": 50
}
π GET /movies/:id
Fetch detailed information about a movie.
- Path Parameters: id: TMDB Movie ID.
π€ Response
{
"id": 550,
"title": "Fight Club",
"overview": "A ticking-time-bomb insomniac...",
"poster_path": "/poster.jpg",
"release_date": "1999-10-15",
"vote_average": 8.4,
"genres": [{"id": 18, "name": "Drama"}]
}
πΎ Favorites Endpoints
π POST /favorites
Add a movie to favorites.
π₯ Request Body
{
"movieId": "550"
}
π€ Response
{
"id": "123",
"movieId": "550",
"title": "Fight Club",
"description": "A ticking-time-bomb insomniac...",
"releaseDate": "1999-10-15",
"tmdbRating": 8.4
}
π GET /favorites
Fetch all favorites for the authenticated user.
- Query Parameters: page (optional): Page number for pagination. limit (optional): Number of items per page.
π€ Response
{
"results": [
{
"id": "123",
"movieId": "550",
"title": "Fight Club",
"description": "A ticking-time-bomb insomniac...",
"releaseDate": "1999-10-15",
"tmdbRating": 8.4
}
],
"total": 10,
"page": 1,
"limit": 10
}
π API Keys Endpoints
π POST /api-keys
Generate a new API key.
π₯ Request Body
{
"description": "Mobile application integration",
"expiresInDays": 30
}
π€ Response
{
"id": "123",
"key": "abcd1234-5678-efgh-ijkl-9876543210mn",
"description": "Mobile application integration",
"expiresAt": "2025-12-31T23:59:59Z",
"createdAt": "2025-07-01T12:00:00Z"
}
π GET /api-keys
Fetch all API keys (Admin only).
π€ Response
[
{
"id": "123",
"description": "Mobile application integration",
"expiresAt": "2025-12-31T23:59:59Z",
"createdAt": "2025-07-01T12:00:00Z",
"isActive": true,
"usageCount": 10
}
]