Skip to content

solomon-mh/task-manager-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API

Task Manager API (PHP + SQLite)

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.


Features

  • CRUD API for tasks
  • SQLite database for persistence
  • Input validation with proper error responses
  • Filtering by status (?status=pending)
  • Dockerized for easy setup

Requirements

  • PHP 8.1+ (if running locally)
  • SQLite (auto-installed with PHP)
  • Docker

Installation and Setup

1. Clone the repository

git clone https://github.com/your-username/task-manager-api.git
cd task-manager-api

2. Run with Docker

  1. Build and run the container:

    docker build -t task-manager-api .
    docker run -p 8000:80 task-manager-api

    Or use Docker Compose:

    docker-compose up --build
  2. Access the API at:

    http://localhost:8000
    

API Endpoints

Task Manager API - Endpoints

1. Register User (POST)

Request

curl -X POST http://localhost:8000/auth/register   -H "Content-Type: application/json"   -d '{"username": "testuser", "password": "testpassword"}'

Response

{
  "message": "User registered"
}

2. Login User (POST)

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"
}

3. Create Task (POST)

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
}

4. Get All Tasks (GET)

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"
  }
]

5. Get Task by ID (GET)

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"
}

6. Update Task (PUT)

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"
}

Error Responses

Examples:

{
  "error": "Task not found"
}
{
  "error": "Authorization header missing"
}
{
  "error": "Invalid or expired token"
}
{
  "error": "Username already exists"
}

Authorization Rules

  • /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"
}

Database Schema

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)


JWT Authentication

This API includes JWT-based authentication by:

  1. Adding a users table with username and password_hash.
  2. Implementing login and registration endpoints.
  3. Generating and verifying JWT tokens for protected routes.

Project Structure

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors