Phase 3 adds a complete REST API layer built with FastAPI, enabling web and mobile client integration while maintaining the existing CLI functionality.
- β FastAPI Framework - Modern, fast, auto-documented API
- β JWT Authentication - Secure token-based auth for all endpoints
- β Full CRUD Operations - Complete task and user management
- β
Automatic OpenAPI Documentation - Swagger UI at
/api/docs - β Input Validation - Pydantic-based request/response validation
- β Error Handling - Comprehensive error responses
- β Pagination - Efficient data fetching with limits
- β CORS Support - Cross-origin requests for web clients
FastAPI Application
βββ Authentication Routes (/api/auth)
β βββ POST /register - User registration
β βββ POST /login - User login (returns JWT)
β βββ POST /refresh-token - Token refresh
βββ Tasks Routes (/api/tasks)
β βββ POST / - Create task
β βββ GET / - List tasks (paginated)
β βββ GET /{id} - Get task details
β βββ PUT /{id} - Update task
β βββ DELETE /{id} - Delete task
βββ Users Routes (/api/users)
β βββ GET /me - Get user profile
β βββ PUT /me - Update profile
β βββ POST /me/toggle-reminders - Toggle reminders
βββ Health & Info
βββ GET / - API info
βββ GET /health - Health check
# Development mode (with auto-reload)
python -m uvicorn task_manager_pro.api.main:app --reload --host 0.0.0.0 --port 8000
# Production mode
python -m uvicorn task_manager_pro.api.main:app --host 0.0.0.0 --port 8000 --workers 4
# View documentation
# Swagger UI: http://localhost:8000/api/docs
# ReDoc: http://localhost:8000/api/redoccurl -X POST "http://localhost:8000/api/auth/register" \
-H "Content-Type: application/json" \
-d '{
"username": "satvik",
"password": "securepass123",
"email": "satvik@example.com"
}'Response (201):
{
"id": "user-uuid",
"username": "satvik",
"email": "satvik@example.com",
"email_reminders_enabled": true,
"created_at": "2025-11-23T12:00:00",
"updated_at": "2025-11-23T12:00:00"
}curl -X POST "http://localhost:8000/api/auth/login" \
-H "Content-Type: application/json" \
-d '{
"username": "satvik",
"password": "securepass123"
}'Response (200):
{
"user": {...},
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer"
}curl -X POST "http://localhost:8000/api/auth/refresh-token" \
-H "Content-Type: application/json" \
-d '{"token": "old_token_here"}'curl -X POST "http://localhost:8000/api/tasks" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Learn FastAPI",
"description": "Read the official docs",
"due_date": "2025-12-31",
"priority": "high"
}'# All tasks
curl -X GET "http://localhost:8000/api/tasks" \
-H "Authorization: Bearer YOUR_TOKEN"
# Pending tasks only
curl -X GET "http://localhost:8000/api/tasks?completed=false" \
-H "Authorization: Bearer YOUR_TOKEN"
# With pagination
curl -X GET "http://localhost:8000/api/tasks?skip=0&limit=10" \
-H "Authorization: Bearer YOUR_TOKEN"Response (200):
{
"total": 5,
"tasks": [
{
"id": "task-uuid",
"title": "Learn FastAPI",
"description": "Read docs",
"due_date": "2025-12-31",
"priority": "high",
"completed": false,
"created_at": "2025-11-23T12:00:00",
"updated_at": "2025-11-23T12:00:00",
"completed_at": null
}
],
"page": 1,
"page_size": 10
}curl -X GET "http://localhost:8000/api/tasks/task-uuid" \
-H "Authorization: Bearer YOUR_TOKEN"curl -X PUT "http://localhost:8000/api/tasks/task-uuid" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Title",
"completed": true,
"priority": "medium"
}'curl -X DELETE "http://localhost:8000/api/tasks/task-uuid" \
-H "Authorization: Bearer YOUR_TOKEN"curl -X GET "http://localhost:8000/api/users/me" \
-H "Authorization: Bearer YOUR_TOKEN"curl -X PUT "http://localhost:8000/api/users/me" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"email": "newemail@example.com",
"email_reminders_enabled": false
}'curl -X POST "http://localhost:8000/api/users/me/toggle-reminders" \
-H "Authorization: Bearer YOUR_TOKEN"task_manager_pro/
βββ api/
β βββ __init__.py
β βββ main.py # FastAPI app initialization
β βββ dependencies.py # JWT auth dependencies
β βββ routes/
β βββ __init__.py
β βββ auth.py # Authentication endpoints
β βββ tasks.py # Task CRUD endpoints
β βββ users.py # User management endpoints
βββ schemas/ # Pydantic models (Phase 2)
βββ storage/ # Database layer (Phase 2)
βββ utils/
βββ security.py # JWT and bcrypt (Phase 2)
βββ ...
- Token Type: HS256 (symmetric)
- Expiration: 30 minutes (configurable)
- Issuer: Configured via
SECRET_KEYenv var - Bearer Token Format:
Authorization: Bearer <token>
- Hashed with bcrypt (12 rounds)
- Never stored or transmitted in plain text
- Validated on login
- Configurable origins via
CORS_ORIGINSenv var - Credentials allowed
- All methods and headers allowed
All errors return proper HTTP status codes:
{
"detail": "Invalid username or password"
}200- Success201- Created204- No Content (deleted)400- Bad Request (validation error)401- Unauthorized (invalid credentials/token)404- Not Found500- Server Error
import httpx
async with httpx.AsyncClient(base_url="http://localhost:8000") as client:
# Register
resp = await client.post("/api/auth/register", json={
"username": "test",
"password": "pass123",
"email": "test@example.com"
})
print(resp.json())
# Login
resp = await client.post("/api/auth/login", json={
"username": "test",
"password": "pass123"
})
token = resp.json()["access_token"]
# Create task
resp = await client.post("/api/tasks",
headers={"Authorization": f"Bearer {token}"},
json={
"title": "Test",
"description": "Test task",
"due_date": "2025-12-31"
}
)
print(resp.json())See tests/test_api.py for comprehensive test examples.
- Pagination: Limited to 100 items per request
- Database Indexes: On user_id, due_date, completed
- Connection Pooling: Automatic via SQLAlchemy
- Async Support: FastAPI handles async naturally
# API
CORS_ORIGINS=http://localhost:3000,http://localhost:8080
# Security (from Phase 2)
SECRET_KEY=your-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Database (from Phase 2)
DATABASE_URL=sqlite:///./tasks.db
SQL_ECHO=false- Add GitHub Actions CI/CD pipeline
- Create comprehensive integration tests
- Add coverage reporting
- Load testing and performance optimization
- Database connection pooling configuration
# Find process using port 8000
lsof -i :8000
# Kill it
kill -9 <PID>
# Or use different port
uvicorn task_manager_pro.api.main:app --port 8001Call /api/auth/refresh-token with current token to get a new one.
Check CORS_ORIGINS env var includes your frontend URL.
SQLite doesn't support concurrent writes. For production, switch to PostgreSQL.