Base URL: https://mdb-api.vercel.app/
This Movie Database API provides endpoints to manage movies, reviews, and user profiles. It supports functionalities like uploading images, creating and retrieving movie details, posting and updating reviews, and user authentication with login, refresh, and logout options.
To use this API, make requests to the base URL followed by the endpoint paths described below. For certain endpoints, authentication is required via token-based authentication.
- Backend: Node.js, Express
- Database: MongoDB
- Image Storage: Cloudinary
- NPM Packages: mongoose, bcrypt, jwt
- Unit Test: jest
- Endpoint:
/api/v1/movies/upload-image - Method: POST
- Params: Form-data with key
image - Returns: File path of the uploaded image.
- Endpoint:
/api/v1/movies - Method: POST
- Body Parameters:
title(string) - Movie titleimageUrl(string) - URL of the movie imagestudio(string) - Movie studio namerunningtime(number) - Running time in minutesgenre(string, optional) - Movie genredirector(string) - Director's nameyear(number) - Release year
- Endpoint:
/api/v1/movies - Method: GET
- Query Parameters:
page(number, optional) - Page number for paginationlimit(number, optional) - Number of results per page
- Endpoint:
/api/v1/movies/:id - Method: GET
- URL Parameters:
id- Movie ID
- Endpoint:
/api/v1/movies/genre/:genre - Method: GET
- URL Parameters:
genre- Movie genre to filter by
- Endpoint:
/api/v1/movies/:id - Method: PUT
- URL Parameters:
id- Movie ID - Body Parameters:
- Similar to the "Create a New Movie" endpoint.
- Endpoint:
/api/v1/movies/:id - Method: DELETE
- URL Parameters:
id- Movie ID
- Endpoint:
/api/v1/movies/:id/reviews - Method: GET
- URL Parameters:
id- Movie ID
- Endpoint:
/api/v1/movies/:id/reviews - Method: POST
- URL Parameters:
id- Movie ID - Body Parameters:
rating(number) - Review ratingreview(string) - Review text
- Endpoint:
/api/v1/movies/reviews/:id - Method: PUT
- URL Parameters:
id- Review ID - Body Parameters:
- Similar to "Create a Review for a Movie".
- Endpoint:
/api/v1/movies/reviews/:id - Method: DELETE
- URL Parameters:
id- Review ID
- Endpoint:
/api/v1/users/upload-profile - Method: POST
- Params: Form-data with key
image - Returns: File path of the uploaded image.
- Endpoint:
/api/v1/users - Method: POST
- Body Parameters:
name(string) - User's nameprofileImageUrl(string) - Profile image URLemail(string) - Email addresspassword(string) - Passwordphonenumber(string, optional) - Phone number
- Endpoint:
/api/v1/users/login - Method: POST
- Body Parameters:
email(string) - Email addresspassword(string) - Password
- Endpoint:
/api/v1/users/refresh - Method: POST
- Body Parameters:
token(string) - Refresh token
- Endpoint:
/api/v1/users/logout - Method: DELETE
- Body Parameters:
token(string) - Token to invalidate
Most of the user-related and review-related endpoints require authentication. The token is provided upon login and should be included in the request header as follows:
Authorization: Bearer <token>The API returns standardized error messages with relevant HTTP status codes for easy debugging. Some of the standard responses include:
- 400 Bad Request: Validation errors or missing required fields
- 401 Unauthorized: Missing or invalid authentication token
- 404 Not Found: Requested resource not found (e.g., invalid movie or review ID)
- 500 Internal Server Error: Server-side issues
Before you begin, ensure you have the following installed on your machine:
- Node.js (version v20.18.0 or higher)
- npm
- MongoDB
- Docker Compose: installed on your system
Clone the repository on your local machine.
git clone git@github.com:KaungZayY/mdb-api.gitcd into cloned repository.
cd mdb-apiCopy the .env.example file as .env
cp .env.example .envSetup the env variables in .env.
npm installRun the Node server
npm run devThe Movie Database API is a robust platform for managing movie information, user-generated reviews, and user accounts. Designed with flexibility and scalability in mind, it provides a full suite of endpoints for interacting with movie data, including functionalities for image uploads, detailed movie metadata, and secure authentication mechanisms.