
- Created FastAPI application with Todo CRUD operations - Implemented GET /api/v1/todos/ for listing todos with pagination - Implemented POST /api/v1/todos/ for creating new todos - Implemented GET /api/v1/todos/{id} for retrieving specific todos - Implemented PUT /api/v1/todos/{id} for updating todos - Implemented DELETE /api/v1/todos/{id} for deleting todos - Added proper error handling with 404 responses - Configured SQLAlchemy with SQLite database - Set up Alembic for database migrations - Added Pydantic schemas for request/response validation - Enabled CORS for all origins - Added health check endpoint at /health - Updated README with complete API documentation
Todo API
A simple Todo API built with FastAPI, SQLAlchemy, and SQLite.
Features
- Full CRUD operations for todos
- RESTful API design
- Automatic API documentation with Swagger/OpenAPI
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- CORS enabled for all origins
- Health check endpoint
API Endpoints
Base Endpoints
GET /
- Root endpoint with API informationGET /health
- Health check endpointGET /docs
- Swagger UI documentationGET /redoc
- ReDoc documentation
Todo Endpoints
All todo endpoints are prefixed with /api/v1/todos
GET /api/v1/todos/
- List all todos (with pagination)- Query parameters:
skip
(default: 0),limit
(default: 100)
- Query parameters:
POST /api/v1/todos/
- Create a new todoGET /api/v1/todos/{todo_id}
- Get a specific todo by IDPUT /api/v1/todos/{todo_id}
- Update a todo by IDDELETE /api/v1/todos/{todo_id}
- Delete a todo by ID
Data Model
Each todo has the following fields:
id
(integer) - Unique identifiertitle
(string, required) - Todo title (1-200 characters)description
(string, optional) - Todo description (max 1000 characters)completed
(boolean) - Completion status (default: false)created_at
(datetime) - Creation timestampupdated_at
(datetime) - Last update timestamp
Quick Start
-
Install dependencies:
pip install -r requirements.txt
-
Start the application:
uvicorn main:app --reload
-
The API will be available at
http://localhost:8000
- API documentation:
http://localhost:8000/docs
- Alternative docs:
http://localhost:8000/redoc
- API documentation:
Database
The application uses SQLite with the database file stored at /app/storage/db/db.sqlite
. Database tables are automatically created when the application starts.
Project Structure
/
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── alembic.ini # Alembic configuration
├── alembic/ # Database migrations
├── app/
│ ├── __init__.py
│ ├── api/ # API routes
│ │ ├── __init__.py
│ │ └── todos.py # Todo CRUD endpoints
│ ├── db/ # Database configuration
│ │ ├── __init__.py
│ │ ├── base.py # SQLAlchemy Base
│ │ └── session.py # Database session management
│ ├── models/ # SQLAlchemy models
│ │ ├── __init__.py
│ │ └── todo.py # Todo model
│ └── schemas/ # Pydantic schemas
│ ├── __init__.py
│ └── todo.py # Todo request/response schemas
Description
Languages
Python
94.7%
Mako
5.3%