This project is a simple Task Management REST API built using pure PHP (no frameworks) with SQLite for database storage. It is fully Dockerized and follows an MVC-like structure.
- CRUD API for tasks
- SQLite database for persistence
- Input validation with proper error responses
- Filtering by status (
?status=pending) - Dockerized for easy setup
- PHP 8.1+ (if running locally)
- SQLite (auto-installed with PHP)
- Docker
git clone https://github.com/your-username/task-manager-api.git
cd task-manager-api-
Build and run the container:
docker build -t task-manager-api . docker run -p 8000:80 task-manager-apiOr use Docker Compose:
docker-compose up --build
-
Access the API at:
http://localhost:8000
Request
curl -X POST http://localhost:8000/auth/register -H "Content-Type: application/json" -d '{"username": "testuser", "password": "testpassword"}'Response
{
"message": "User registered"
}Request
curl -X POST http://localhost:8000/auth/login -H "Content-Type: application/json" -d '{"username": "testuser", "password": "testpassword"}'Response
{
"token": "your_jwt_token_here"
}Request
curl -X POST http://localhost:8000/tasks -H "Content-Type: application/json" -H "Authorization: Bearer your_jwt_token_here" -d '{"title": "Test Task", "description": "This is a sample task"}'Response
{
"message": "Task created",
"id": 1
}Request
curl http://localhost:8000/tasks -H "Authorization: Bearer your_jwt_token_here"With filtering
curl http://localhost:8000/tasks?status=completed -H "Authorization: Bearer your_jwt_token_here"Response
[
{
"id": 1,
"title": "Test Task",
"description": "This is a sample task",
"status": "pending",
"created_at": "2025-08-04 08:00:00",
"updated_at": "2025-08-04 08:00:00"
}
]Request
curl http://localhost:8000/tasks/1 -H "Authorization: Bearer your_jwt_token_here"Response
{
"id": 1,
"title": "Test Task",
"description": "This is a sample task",
"status": "pending",
"created_at": "2025-08-04 08:00:00",
"updated_at": "2025-08-04 08:00:00"
}Request
curl -X PUT http://localhost:8000/tasks/1 -H "Content-Type: application/json" -H "Authorization: Bearer your_jwt_token_here" -d '{"title": "Updated Task", "description": "Updated description", "status": "completed"}'Response
{
"message": "Task updated"
}Examples:
{
"error": "Task not found"
}{
"error": "Authorization header missing"
}{
"error": "Invalid or expired token"
}{
"error": "Username already exists"
}- /auth/register and /auth/login are public endpoints (no token required).
- All /tasks endpoints require an Authorization header with a valid JWT token:
-H "Authorization: Bearer your_jwt_token_here"Examples:
{
"error": "Task not found"
}{
"error": "Title and description are required"
}Each task has the following fields:
id(auto-increment)title(string)description(text)status(enum: pending, in-progress, completed)created_at(timestamp)updated_at(timestamp)
This API includes JWT-based authentication by:
- Adding a
userstable withusernameandpassword_hash. - Implementing login and registration endpoints.
- Generating and verifying JWT tokens for protected routes.
task-manager-api/
├── src/
│ ├── Controllers/ # Handles request logic
│ ├── Database/ # Database connection and initialization
│ ├── Models/ # Database models (Task, User)
│ └── Routes/ # API route definitions
├── config/
│ └── apache.conf # Apache virtual host configuration
├── Dockerfile # Docker build file
├── docker-compose.yml # Docker compose for services
├── index.php # API entry point (front controller)
├── .env # Environment variables (JWT_SECRET)
├── .htaccess # Apache rewrite rules for clean URLs
└── README.md # Documentation