
- Set up FastAPI application with CORS support - Created SQLAlchemy models and database session management - Implemented CRUD endpoints for todos with proper validation - Added Alembic migrations for database schema - Included health check and base information endpoints - Added comprehensive README with API documentation - Configured Ruff for code quality and linting
Todo App API
A simple Todo application API built with FastAPI and SQLite.
Features
- ✅ Create, read, update, and delete todos
- ✅ RESTful API design
- ✅ SQLite database with SQLAlchemy ORM
- ✅ Database migrations with Alembic
- ✅ API documentation with Swagger UI
- ✅ CORS support for frontend integration
- ✅ Health check endpoint
- ✅ Pydantic schemas for data validation
API Endpoints
Base Endpoints
GET /
- API information and linksGET /health
- Health check endpoint
Todo Endpoints
GET /api/v1/todos/
- List all todos (with pagination)POST /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 todo
Installation
- Install dependencies:
pip install -r requirements.txt
Running the Application
- Start the development server:
uvicorn main:app --reload
-
Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
-
Health check:
Database
The application uses SQLite database stored at /app/storage/db/db.sqlite
.
Database Migrations
Database migrations are managed with Alembic:
# Create a new migration
alembic revision --autogenerate -m "Description of changes"
# Apply migrations
alembic upgrade head
# Downgrade migrations
alembic downgrade -1
Project Structure
├── README.md
├── requirements.txt
├── main.py # FastAPI application entry point
├── alembic.ini # Alembic configuration
├── alembic/ # Database migrations
│ ├── versions/
│ ├── env.py
│ └── script.py.mako
└── app/
├── api/
│ └── todos.py # Todo API endpoints
├── db/
│ ├── base.py # SQLAlchemy base
│ └── session.py # Database session
├── models/
│ └── todo.py # Todo database model
└── schemas/
└── todo.py # Pydantic schemas
Todo Model
Each todo has the following fields:
id
(int): Unique identifiertitle
(str): Todo title (required)description
(str): Optional descriptioncompleted
(bool): Completion status (default: false)created_at
(datetime): Creation timestampupdated_at
(datetime): Last update timestamp
Development
Code Quality
The project uses Ruff for linting and code formatting:
# Run linting
ruff check .
# Auto-fix issues
ruff check . --fix
API Usage Examples
Create a Todo
curl -X POST "http://localhost:8000/api/v1/todos/" \
-H "Content-Type: application/json" \
-d '{"title": "Buy groceries", "description": "Milk, bread, eggs"}'
List Todos
curl "http://localhost:8000/api/v1/todos/"
Update a Todo
curl -X PUT "http://localhost:8000/api/v1/todos/1" \
-H "Content-Type: application/json" \
-d '{"completed": true}'
Delete a Todo
curl -X DELETE "http://localhost:8000/api/v1/todos/1"
License
This project is open source and available under the MIT License.
Description
Languages
Python
94.7%
Mako
5.3%