
- Add project structure with FastAPI, SQLAlchemy, and Alembic - Implement Todo model with CRUD operations - Add REST API endpoints for todo management - Configure SQLite database with migrations - Include health check and API documentation endpoints - Add CORS middleware for all origins - Format code with Ruff
2.3 KiB
2.3 KiB
Simple Todo API
A simple todo application built with FastAPI and SQLite.
Features
- Create, read, update, and delete todos
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- FastAPI with automatic OpenAPI documentation
- CORS enabled for all origins
- Health check endpoint
API Endpoints
GET /
- Root endpoint with basic informationGET /health
- Health check endpointGET /docs
- Interactive API documentation (Swagger UI)GET /redoc
- Alternative API documentationGET /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 specific todoDELETE /api/v1/todos/{todo_id}
- Delete a specific todo
Installation
- Install the dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
Project Structure
├── app/
│ ├── api/
│ │ └── v1/
│ │ ├── __init__.py
│ │ └── todos.py
│ ├── crud/
│ │ ├── __init__.py
│ │ └── todo.py
│ ├── db/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ └── session.py
│ ├── models/
│ │ ├── __init__.py
│ │ └── todo.py
│ ├── schemas/
│ │ ├── __init__.py
│ │ └── todo.py
│ └── __init__.py
├── alembic/
│ ├── versions/
│ │ └── 001_initial_todo_table.py
│ ├── env.py
│ └── script.py.mako
├── alembic.ini
├── main.py
├── requirements.txt
└── README.md
Database
The application uses SQLite database stored at /app/storage/db/db.sqlite
. The database schema is managed using Alembic migrations.
Todo Model
Each todo has the following fields:
id
: Unique identifier (auto-generated)title
: Todo title (required, max 200 characters)description
: Todo description (optional, max 500 characters)completed
: Completion status (boolean, default: false)created_at
: Creation timestampupdated_at
: Last update timestamp