Automated Action a4fb722622 Implement complete Todo API with FastAPI
- 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
2025-06-20 02:31:29 +00:00
2025-06-20 02:23:06 +00:00

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 links
  • GET /health - Health check endpoint

Todo Endpoints

  • GET /api/v1/todos/ - List all todos (with pagination)
  • POST /api/v1/todos/ - Create a new todo
  • GET /api/v1/todos/{todo_id} - Get a specific todo
  • PUT /api/v1/todos/{todo_id} - Update a todo
  • DELETE /api/v1/todos/{todo_id} - Delete a todo

Installation

  1. Install dependencies:
pip install -r requirements.txt

Running the Application

  1. Start the development server:
uvicorn main:app --reload
  1. Access the API documentation:

  2. 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 identifier
  • title (str): Todo title (required)
  • description (str): Optional description
  • completed (bool): Completion status (default: false)
  • created_at (datetime): Creation timestamp
  • updated_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
Project: Todo App
Readme 47 KiB
Languages
Python 94.7%
Mako 5.3%