# FastAPI Todo App A simple Todo API built with FastAPI and SQLite. ## Features - 📝 **Todo Management**: Create, read, update, and delete todo items - 🔍 **Filtering & Pagination**: Filter todos by completion status and paginate results - 📊 **Health Monitoring**: Endpoint to check application and database health - 🔧 **Environment Variables**: Access to environment variables via API - 🛡️ **Error Handling**: Comprehensive error handling with meaningful messages - 📚 **API Documentation**: Auto-generated Swagger/OpenAPI documentation ## Tech Stack - **FastAPI**: Modern, fast (high-performance) web framework for building APIs - **SQLAlchemy**: SQL toolkit and Object-Relational Mapping (ORM) - **Alembic**: Database migration tool - **SQLite**: Lightweight, file-based database - **Pydantic**: Data validation and settings management - **Uvicorn**: ASGI server for running the application ## Project Structure ``` ├── app/ │ ├── api/ │ │ └── v1/ │ │ ├── env_vars.py # Environment variables endpoints │ │ ├── health.py # Health check endpoint │ │ ├── router.py # API router │ │ └── todos.py # Todo CRUD endpoints │ ├── core/ │ │ ├── config.py # Application configuration │ │ └── exceptions.py # Custom exception handlers │ ├── database/ │ │ └── session.py # Database session setup │ ├── models/ │ │ └── todo.py # SQLAlchemy models │ └── schemas/ │ └── todo.py # Pydantic schemas ├── migrations/ # Alembic migration files ├── alembic.ini # Alembic configuration ├── main.py # Application entry point └── requirements.txt # Project dependencies ``` ## Setup Instructions ### Prerequisites - Python 3.8+ - pip (Python package installer) ### Installation 1. Clone the repository: ```bash git clone cd todoapp-us6a2a ``` 2. Install dependencies: ```bash pip install -r requirements.txt ``` 3. Create the database and run migrations: ```bash alembic upgrade head ``` ### Running the Application Start the application with: ```bash uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` The API will be available at: http://localhost:8000 ## API Documentation Interactive API documentation is available at: - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## API Endpoints ### Health Check - `GET /health` - Check application health ### Todo Endpoints - `GET /api/v1/todos` - List all todos (with optional filtering and pagination) - `POST /api/v1/todos` - Create a new todo - `GET /api/v1/todos/{todo_id}` - Get a specific todo - `PATCH /api/v1/todos/{todo_id}` - Update a todo - `DELETE /api/v1/todos/{todo_id}` - Delete a todo ### Environment Variables Endpoints - `GET /api/v1/env/content` - Get the value of the CONTENT environment variable ## Example Usage ### Create a Todo ```bash curl -X 'POST' \ 'http://localhost:8000/api/v1/todos/' \ -H 'Content-Type: application/json' \ -d '{ "title": "Learn FastAPI", "description": "Build a sample todo app", "completed": false }' ``` ### List All Todos ```bash curl -X 'GET' 'http://localhost:8000/api/v1/todos/' ``` ### Get a Specific Todo ```bash curl -X 'GET' 'http://localhost:8000/api/v1/todos/1' ``` ### Update a Todo ```bash curl -X 'PATCH' \ 'http://localhost:8000/api/v1/todos/1' \ -H 'Content-Type: application/json' \ -d '{ "completed": true }' ``` ### Delete a Todo ```bash curl -X 'DELETE' 'http://localhost:8000/api/v1/todos/1' ``` ### Get CONTENT Environment Variable ```bash curl -X 'GET' 'http://localhost:8000/api/v1/env/content' ``` To set the environment variable before running the application: ```bash export CONTENT="Your content here" uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` ## License This project is licensed under the MIT License.