Todo List API
A simple Todo List API built with FastAPI and SQLite.
Features
- Create, read, update, and delete todo items
- Filter todo items by completion status
- Pagination support
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Health check endpoint
- OpenAPI documentation
Project Structure
todo-list-api/
├── alembic.ini # Alembic configuration
├── app/ # Main application package
│ ├── api/ # API endpoints
│ │ └── routes/ # API route handlers
│ │ ├── health.py # Health check endpoint
│ │ └── todo.py # Todo endpoints
│ ├── core/ # Core application code
│ │ └── config.py # Application configuration
│ ├── crud/ # CRUD operations
│ │ └── todo.py # Todo CRUD operations
│ ├── db/ # Database related code
│ │ └── session.py # Database session setup
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ └── schemas/ # Pydantic schemas
│ └── todo.py # Todo schemas
├── main.py # Application entry point
├── migrations/ # Alembic migrations
│ ├── env.py # Alembic environment configuration
│ ├── script.py.mako # Migration script template
│ └── versions/ # Migration script versions
│ └── 001_create_todos_table.py # Initial migration
└── requirements.txt # Python dependencies
Requirements
- Python 3.9+
- FastAPI
- SQLAlchemy
- Pydantic
- Alembic
- Uvicorn
Installation
- Clone the repository:
git clone https://github.com/yourusername/todo-list-api.git
cd todo-list-api
- Install the required dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
Running the Application
Start the application with:
uvicorn main:app --reload
The API will be available at http://localhost:8000
.
API Documentation
After starting the application, you can access the interactive API documentation:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
API Endpoints
Health Check
GET /api/health
: Check if the API is healthy
Todo Operations
-
GET /api/todos
: Get a list of todo items- Query parameters:
skip
: Number of items to skip (pagination)limit
: Maximum number of items to return (pagination)completed
: Filter by completion status (optional)
- Query parameters:
-
POST /api/todos
: Create a new todo item- Request body:
TodoCreate
schema
- Request body:
-
GET /api/todos/{todo_id}
: Get a specific todo item by ID -
PUT /api/todos/{todo_id}
: Update a specific todo item by ID- Request body:
TodoUpdate
schema
- Request body:
-
DELETE /api/todos/{todo_id}
: Delete a specific todo item by ID
Examples
Create a Todo
curl -X 'POST' \
'http://localhost:8000/api/todos' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, eggs, bread",
"completed": false
}'
Get All Todos
curl -X 'GET' 'http://localhost:8000/api/todos'
Get Completed Todos
curl -X 'GET' 'http://localhost:8000/api/todos?completed=true'
Update a Todo
curl -X 'PUT' \
'http://localhost:8000/api/todos/1' \
-H 'Content-Type: application/json' \
-d '{
"completed": true
}'
Delete a Todo
curl -X 'DELETE' 'http://localhost:8000/api/todos/1'
License
MIT
Description
Languages
Python
95.3%
Mako
4.7%