A Laravel-based RESTful API for managing movies and user watch lists.
- User authentication
- CRUD operations for movies
- Watch later functionality
- PHP 8.2+
- Composer
- Laravel 11.x
- SQLite 3
-
Clone the repository:
git clone https://github.com/mrlibelula/movie-api.git cd movie-api -
Install dependencies:
composer install -
Copy the .env.example file to .env and configure your database:
cp .env.example .env -
Update the .env file to use SQLite:
DB_CONNECTION=sqlite DB_DATABASE=/absolute/path/to/your/database.sqlite -
Create an empty SQLite database file:
touch database/database.sqlite -
Generate application key:
php artisan key:generate -
Run migrations:
php artisan migrate -
[Optional] Seed the database:
php artisan db:seed
Start the development server:
php artisan serve
You can now access the API at http://localhost:8000.
- POST
/api/register - Body:
{ "name": "string", "email": "string", "password": "string", "password_confirmation": "string" } - Response: User details and token
- POST
/api/login - Body:
{ "email": "string", "password": "string" } - Response: User details and token
- GET
/api/movies - Response: List of all movies
- POST
/api/movies - Body:
{ "title": "string", "description": "string", "release_date": "YYYY-MM-DD", "genre_id": "integer" } - Response: Created movie details
- GET
/api/movies/{id} - Response: Movie details
- PUT
/api/movies/{id} - Body:
{ "title": "string", "description": "string", "release_date": "YYYY-MM-DD", "genre_id": "integer" } - Response: Updated movie details
- DELETE
/api/movies/{id} - Response: Success message
- POST
/api/movies/{id}/watch-later - Response: Success message (or
409if the movie is already on the list)
- DELETE
/api/movies/{id}/watch-later - Response: Success message (or
404if the movie is not on the list)
- GET
/api/watch-later - Response: List of movies in the user's watch later list
All endpoints except /api/register and /api/login require authentication. Include the bearer token in the Authorization header:
Authorization: Bearer {token}
All endpoints may return the following error responses:
400 Bad Request: Invalid input data401 Unauthorized: Invalid or missing authentication token403 Forbidden: User doesn't have permission to perform the action404 Not Found: Requested resource not found422 Unprocessable Entity: Validation errors500 Internal Server Error: Server-side error
Run the test suite with:
php artisan test
You can access the live demo of this project using the following base URL and endpoints:
Base URL: https://libe.dev/demo/movie-api/api
Endpoints:
/register/login/logout/movies/movies/{id}/movies/{id}/watch-later/watch-later
Example full URL: https://libe.dev/demo/movie-api/api/register
Please note that these endpoints are for demonstration purposes only. Refer to the API documentation for full details on request/response formats and authentication requirements.
To interact with these endpoints, we recommend using Postman, a popular API development and testing tool.
You can download Postman here: https://www.postman.com/downloads/
Postman allows you to easily send requests to the API endpoints and view the responses, making it an ideal tool for exploring and testing the functionality of this Movie API.