GET
/movies
List all movies
Example Request
Query Parameters
page (number) - Page number (default: 1)
limit (number) - Items per page (default: 10, max: 100)
genre (string) - Filter by genre (e.g., 'action', 'drama')
year (number) - Filter by release year
search (string) - Search in title and description
sort (string) - Sort by field (e.g., 'title', 'year', 'rating')
order (string) - Sort order ('asc' or 'desc', default: 'desc')
Example Request
GET /api/v1/movies?page=1&limit=10&genre=drama&year=2020&sort=rating&order=desc
Example Response (200 OK)
{
"success": true,
"page": 1,
"total_pages": 100,
"total_results": 1000,
"results": [
{
"id": "tt0111161",
"title": "The Shawshank Redemption",
"year": 1994,
"rating": 9.3,
"genres": ["Drama"],
"poster": "https://via.placeholder.com/300x450",
"createdAt": "2023-01-15T10:30:00Z",
"updatedAt": "2023-01-15T10:30:00Z"
}
]
}
Error Responses
401 Unauthorized
{
"success": false,
"error": "No token provided"
}
400 Bad Request
{
"success": false,
"error": "Invalid query parameters",
"details": {
"year": "Year must be a number"
}
}
GET
/movies/:id
Get movie details
Example Request
URL Parameters
id (string) - Movie ID (IMDB ID or internal ID)
Example Request
GET /api/v1/movies/tt0111161
Example Response (200 OK)
{
"success": true,
"data": {
"id": "tt1375666",
"title": "Inception",
"year": 2010,
"rated": "PG-13",
"released": "2010-07-16",
"runtime": 148,
"genres": ["Action", "Adventure", "Sci-Fi"],
"director": "Christopher Nolan",
"writer": "Christopher Nolan",
"actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Ellen Page"],
"plot": "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O., but his tragic past may doom the project and his team to disaster.",
"language": "English, Japanese, French",
"country": "United States, United Kingdom",
"awards": "Won 4 Oscars. 159 wins & 220 nominations total",
"poster_url": "https://api.moviedb.example.com/uploads/posters/tt1375666.jpg",
"backdrop_url": "https://api.moviedb.example.com/uploads/backdrops/tt1375666.jpg",
"ratings": [
{ "source": "Internet Movie Database", "value": "8.8/10" },
{ "source": "Rotten Tomatoes", "value": "87%" },
{ "source": "Metacritic", "value": "74/100" }
],
"metascore": "74",
"imdb_rating": 8.8,
"imdb_votes": 2483527,
"imdb_id": "tt1375666",
"type": "movie",
"dvd": "07 Dec 2010",
"box_office": "$292,576,195",
"production": "Warner Bros. Pictures, Legendary Pictures, Syncopy",
"website": "http://inceptionmovie.warnerbros.com/",
"created_at": "2023-01-15T10:30:00Z",
"updated_at": "2023-01-15T10:30:00Z"
}
}
Error Responses
404 Not Found
{
"success": false,
"error": "Movie not found"
}
PUT
/api/v1/movies/:id
Update a movie (Admin only)
Request Body (JSON)
{
"plot": "Updated plot description...",
"rating": 8.8
}
Example Response (200 OK)
{
"success": true,
"data": {
"id": "tt1375666",
"title": "Inception",
"plot": "Updated plot description...",
"rating": 8.8,
"updatedAt": "2023-01-16T14:30:00Z"
}
}
🛠️ Implementation Notes
Backend Setup (Node.js + Express)
1. Install required packages:
npm install express multer jsonwebtoken
2. Configure multer for file uploads:
const multer = require('multer');
const path = require('path');
// Configure storage
const storage = multer.diskStorage({
destination: function (req, file, cb) {
let dir = 'uploads/';
if (file.fieldname === 'poster') {
dir += 'posters/';
} else if (file.fieldname === 'backdrop') {
dir += 'backdrops/';
}
require('fs').mkdirSync(dir, { recursive: true });
cb(null, dir);
},
filename: function (req, file, cb) {
// Use movie ID if available, otherwise generate a unique name
const movieId = req.params.id || Date.now();
const ext = path.extname(file.originalname).toLowerCase();
cb(null, `${movieId}${ext}`);
}
});
// File filter to accept only images
const fileFilter = (req, file, cb) => {
const allowedTypes = ['.jpg', '.jpeg', '.png', '.webp'];
const ext = path.extname(file.originalname).toLowerCase();
if (allowedTypes.includes(ext)) {
return cb(null, true);
}
cb(new Error('Invalid file type. Only jpg, jpeg, png, webp are allowed.'));
};
// Initialize multer with configuration
const upload = multer({
storage: storage,
fileFilter: fileFilter,
limits: {
fileSize: 5 * 1024 * 1024, // 5MB limit
files: 2 // Max 2 files (poster and backdrop)
}
});
// Middleware for handling file uploads
const uploadMovieImages = upload.fields([
{ name: 'poster', maxCount: 1 },
{ name: 'backdrop', maxCount: 1 }
]);
Example Route Implementation
// Create movie with image uploads
router.post('/movies', authenticateJWT, isAdmin, uploadMovieImages, async (req, res) => {
try {
const movieData = req.body;
// Process uploaded files
if (req.files) {
if (req.files.poster) {
movieData.poster_url = `/uploads/posters/${req.files.poster[0].filename}`;
}
if (req.files.backdrop) {
movieData.backdrop_url = `/uploads/backdrops/${req.files.backdrop[0].filename}`;
}
}
// Process genres if sent as comma-separated string
if (typeof movieData.genres === 'string') {
movieData.genres = movieData.genres.split(',').map(g => g.trim());
}
// Process actors if sent as comma-separated string
if (typeof movieData.actors === 'string') {
movieData.actors = movieData.actors.split(',').map(a => a.trim());
}
// Create movie in database
const movie = await Movie.create(movieData);
res.status(201).json({
success: true,
data: movie
});
} catch (error) {
console.error('Error creating movie:', error);
res.status(400).json({
success: false,
error: 'VALIDATION_ERROR',
message: error.message
});
}
});
Getting Started
To start using the MovieDB API:
- Sign up at developer.moviedb.example.com to get your API key
- Include the JWT token in the Authorization header of your requests
- Use multipart/form-data for file uploads
- Start making requests to the API endpoints
For support, contact support@moviedb.example.com