FastAPI Todo App
This is a simple Todo API application built with FastAPI and SQLite. The application allows you to create, read, update, and delete Todo items.
Features
- Create new todo items
- Retrieve all todo items
- Retrieve a specific todo item by ID
- Update todo items
- Delete todo items
- Health check endpoint
Tech Stack
- FastAPI: High-performance web framework
- SQLAlchemy: SQL toolkit and ORM
- Alembic: Database migration tool
- SQLite: Lightweight disk-based database
- Pydantic: Data validation and settings management
- Uvicorn: ASGI server
Project Structure
.
├── alembic.ini # Alembic configuration
├── main.py # FastAPI application entry point
├── migrations/ # Database migrations
│ ├── env.py # Alembic environment
│ ├── README # Alembic readme
│ ├── script.py.mako # Alembic script template
│ └── versions/ # Migration scripts
│ └── 001_create_todo_table.py # Initial migration
├── app/ # Application package
│ ├── api/ # API endpoints
│ │ ├── api.py # API router
│ │ ├── deps.py # Dependencies
│ │ └── endpoints/ # Endpoint modules
│ │ └── todos.py # Todo endpoints
│ ├── core/ # Core modules
│ │ ├── config.py # Configuration
│ │ └── exceptions.py # Custom exceptions
│ ├── crud/ # CRUD operations
│ │ └── crud_todo.py # Todo CRUD operations
│ ├── db/ # Database
│ │ ├── base.py # Base class
│ │ ├── base_class.py # Import all models
│ │ └── session.py # Database session
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ └── schemas/ # Pydantic schemas
│ └── todo.py # Todo schemas
└── requirements.txt # Project dependencies
Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run the application:
uvicorn main:app --reload
API Documentation
Once the application is running, you can access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
GET /api/v1/todos/
: Get all todosPOST /api/v1/todos/
: Create a new todoGET /api/v1/todos/{todo_id}
: Get a specific todoPUT /api/v1/todos/{todo_id}
: Update a todoDELETE /api/v1/todos/{todo_id}
: Delete a todoGET /health
: Health check endpoint
Example Usage
Create a Todo
curl -X POST "http://localhost:8000/api/v1/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/v1/todos/"
Get a Specific Todo
curl -X GET "http://localhost:8000/api/v1/todos/1"
Update a Todo
curl -X PUT "http://localhost:8000/api/v1/todos/1" \
-H "Content-Type: application/json" \
-d '{"title": "Buy groceries", "description": "Milk, eggs, bread, cheese", "completed": true}'
Delete a Todo
curl -X DELETE "http://localhost:8000/api/v1/todos/1"
Health Check
curl -X GET "http://localhost:8000/health"
Description
Languages
Python
95.9%
Mako
4.1%