Todo API

A simple Todo API built with FastAPI and SQLite.

Features

  • Create, read, update, and delete todo items
  • Filter todos by completion status
  • Pagination support
  • SQLite database with SQLAlchemy ORM
  • Database migrations with Alembic
  • API documentation with Swagger UI and ReDoc
  • Health check endpoint

Project Structure

todoapp/
├── alembic.ini                  # Alembic configuration
├── app/                         # Application package
│   ├── api/                     # API endpoints
│   │   ├── endpoints/           # API endpoint modules
│   │   │   ├── health.py        # Health check endpoint
│   │   │   └── todos.py         # Todo endpoints
│   │   └── api.py               # API router
│   ├── core/                    # Core modules
│   │   └── config.py            # Application configuration
│   ├── crud/                    # CRUD operations
│   │   └── todo.py              # Todo CRUD operations
│   ├── db/                      # Database modules
│   │   └── session.py           # Database session setup
│   ├── models/                  # SQLAlchemy models
│   │   └── todo.py              # Todo model
│   └── schemas/                 # Pydantic schemas
│       └── todo.py              # Todo schemas
├── main.py                      # Application entry point
├── migrations/                  # Alembic migrations
│   ├── versions/                # Migration versions
│   └── env.py                   # Alembic environment
└── requirements.txt             # Python dependencies

Getting Started

Prerequisites

  • Python 3.8 or higher

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd todoapp
    
  2. Install the required packages:

    pip install -r requirements.txt
    
  3. Run the database migrations:

    alembic upgrade head
    
  4. Start the application:

    uvicorn main:app --reload
    
  5. The API will be available at http://localhost:8000

API Endpoints

Health Check

  • GET /api/v1/health: Check the API status

Todo Endpoints

  • GET /api/v1/todos: List all todos (with optional filtering and pagination)

    • Query parameters:
      • skip: Number of records to skip (default: 0)
      • limit: Maximum number of records to return (default: 100)
      • completed: Filter by completion status (optional)
  • POST /api/v1/todos: Create a new todo

    • Request body:
      {
        "title": "string",
        "description": "string (optional)",
        "completed": false
      }
      
  • GET /api/v1/todos/{todo_id}: Get a specific todo by ID

  • PATCH /api/v1/todos/{todo_id}: Update a specific todo

    • Request body (all fields optional):
      {
        "title": "string",
        "description": "string",
        "completed": true
      }
      
  • DELETE /api/v1/todos/{todo_id}: Delete a specific todo

Development

Database Migrations

To create a new migration after modifying the models:

alembic revision --autogenerate -m "description of changes"
alembic upgrade head

Running Tests

Tests can be run using pytest:

pytest

License

This project is licensed under the MIT License.

Description
Project: Todo App
Readme 43 KiB
Languages
Python 96.7%
Mako 3.3%