This project was created following these instructions: https://github.com/harshalpatel/take-home-coding . It corresponds to a Node.js application that provides an API endpoint to retrieve a list of movies released in a specified year, sorted by descending popularity. Each movie in the list includes the title, release date, vote average, and a list of editors. The API integrates with The Movie Database (TMDB) APIs to fetch movie and credit information. Robust testing is included.
- Features
- Prerequisites
- Installation
- Environment Variables
- Running the Application
- API Documentation
- Running Tests
- Technologies Used
- Project Structure
- License
- Contact Information
- Fetches movies for a given year, sorted by popularity.
- Retrieves editors for each movie (optional if the credits API fails).
- Returns movie details including title, release date, vote average, and editors.
- Handles API failures gracefully without crashing the service.
- Includes comprehensive unit tests.
- Node.js v21 or higher: Ensure you have Node.js installed. You can download it from Node.js Official Website.
- npm: Comes bundled with Node.js.
-
Clone the repository:
git clone https://github.com/DiegoGonzalezCruz/home-assessment-cvs.git cd movie-information-api
-
Install dependencies:
npm install
The application requires a TMDB API bearer token to authenticate requests. Do not commit your bearer token to the repository.
Create a .env file in the root directory:
touch .env
TMDB_API_KEY=your_tmdb_bearer_token
- Replace your_tmdb_bearer_token with your actual TMDB bearer token.
- You can obtain an API key by creating an account on The Movie Database.
Start the server:
npm start
The server will run on port 3000 by default.
Endpoint URL: /movies/:year Method: GET URL Parameters: year: The year in YYYY format. Query Parameters: page (optional): The page number of results to retrieve. Defaults to 1 if not provided. Response Format The API returns a JSON array of movie objects with the following structure:
[
{
"title": "Movie Title",
"release_date": "Release Date in 'Month Day, Year' format",
"vote_average": 8.19,
"editors": ["Editor One", "Editor Two"]
}
]
GET http://localhost:3000/movies/2019?page=1 Example Response:
[
{
"title": "Joker",
"release_date": "October 4, 2019",
"vote_average": 8.19,
"editors": [
"Jeff Groth",
"Jeff Mee",
"Ray Neapolitan",
"Thomas J. Cabela"
]
},
{
"title": "Avengers: Endgame",
"release_date": "April 26, 2019",
"vote_average": 8.27,
"editors": ["Jeffrey Ford", "Matthew Schmidt"]
}
// Additional movie objects...
]
Invalid Year Format:
{
"error": "Invalid year format. Please use YYYY"
}
{
"error": "Invalid page number. Must be a positive integer."
}
{
"error": "Internal Server Error"
}
The project includes unit tests to ensure functionality remains intact.
Run tests using the following command:
npm test
The tests cover scenarios including successful data retrieval, API failures, movies without editors, and partial failures.
-
Node.js: JavaScript runtime environment.
-
TypeScript: Typed superset of JavaScript.
-
Express: Web framework for Node.js.
-
Axios: Promise-based HTTP client.
-
dotenv: Loads environment variables from a .env file.
-
Jest: JavaScript testing framework.
├── src
│ ├── index.ts // Entry point of the application
│ ├── movies.ts // Module handling movie data fetching and processing
│ └── movies.test.ts // Unit tests for movies module
├── .env // Environment variables (not committed to version control)
├── package.json // Project metadata and dependencies
├── tsconfig.json // TypeScript configuration
└── README.md // Project documentation
This project is licensed under the MIT License.
For any questions or suggestions, please contact:
Name: Diego Gonzalez Cruz
Email: [email protected]