A lightweight, in-memory CRUD To-Do List API built using Python, FastAPI, and Pydantic.
- In-Memory Storage: Fast execution with zero database setup required.
- Full CRUD Support: Create, Read, Update, and Delete tasks.
- Input Validation: Rejects empty or invalid task titles with proper error codes.
- Interactive Documentation: Auto-generated Swagger UI.
| Method | Path | Description | Status Codes |
|---|---|---|---|
| GET | / |
API Root self-description | 200 OK |
| GET | /health |
Server health check | 200 OK |
| GET | /tasks |
List all tasks | 200 OK |
| GET | /tasks/{id} |
Get a single task by ID | 200 OK, 404 Not Found |
| POST | /tasks |
Create a new task | 201 Created, 400 Bad Request |
| PUT | /tasks/{id} |
Update an existing task | 200 OK, 400 Bad Request, 404 Not Found |
| DELETE | /tasks/{id} |
Remove a task | 204 No Content, 404 Not Found |
- Clone the repository:
git clone [https://github.com/ahmadrayan-create/task-api.git](https://github.com/ahmadrayan-create/task-api.git) cd task-api
2. **Create and activate a virtual environment:**
```bash
python -m venv venv
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Start the server:
uvicorn main:app --reload --port 8000
- Open Swagger UI:
Navigate to
http://localhost:8000/docsin your browser.
PS C:\Users\iamom> irm -Method POST -Uri "http://localhost:8000/tasks" -ContentType "application/json" -Body '{"title":"Test task"}'
id title done
-- ----- ----
4 Test task False
An upgraded, persistent CRUD To-Do List API built using Python, FastAPI, SQLModel, and SQLite.
This repository contains the evolution of Assignment 1 (BE-01: In-Memory CRUD API) into a production-ready database-backed application for Assignment 2 (BE-02):
- Assignment 1: Data lived strictly in a temporary memory list and was wiped out on every server restart.
- Assignment 2 (Current): Replaced the in-memory array with a lightweight, file-based SQLite database (
tasks.db) managed via SQLModel. Data now securely persists across server restarts while keeping the exact same API contract.
- Persistent SQLite Storage: Tasks are saved to a local
tasks.dbfile and survive server reboots. - Automatic Schema & Seeding: Tables are created automatically on startup, and pre-seeded with 3 initial tasks only if the database is empty.
- Full CRUD Support: Create (
POST), Read (GET), Update (PUT), and Delete (DELETE) tasks. - Input Validation: Rejects empty or invalid task titles with proper
400 Bad Requeststatus codes. - Interactive Documentation: Auto-generated Swagger UI available out-of-the-box.
| Method | Path | Description | Status Codes |
|---|---|---|---|
| GET | / |
API Root self-description | 200 OK |
| GET | /health |
Server health check | 200 OK |
| GET | /tasks |
List all tasks from SQLite | 200 OK |
| GET | /tasks/{id} |
Get a single task by ID | 200 OK, 404 Not Found |
| POST | /tasks |
Create a new task in database | 201 Created, 400 Bad Request |
| PUT | /tasks/{id} |
Update an existing task | 200 OK, 400 Bad Request, 404 Not Found |
| DELETE | /tasks/{id} |
Remove a task from database | 204 No Content, 404 Not Found |
- Clone the repository:
git clone [https://github.com/ahmadrayan-create/task-api.git](https://github.com/ahmadrayan-create/task-api.git) cd task-api
2. **Create and activate a virtual environment:**
```bash
python -m venv venv
# Windows PowerShell:
venv\Scripts\Activate.ps1
# Mac/Linux:
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Start the server:
uvicorn main:app --reload --port 8000
(Note: The tasks.db file will automatically be created and seeded in your root directory upon startup).
5. Open Swagger UI:
Navigate to http://localhost:8000/docs in your browser.
Testing database write and persistence:
# Create a new task
$body = @{ title = "Test database write" } | ConvertTo-Json
irm -Uri "http://localhost:8000/tasks" -Method Post -ContentType "application/json" -Body $body
# Output response:
# id title done
# -- ----- ----
# 4 Test database write False