102 lines
2.9 KiB
Markdown
102 lines
2.9 KiB
Markdown
# Todo API
|
|
|
|
A simple REST API for managing todo items built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todo items
|
|
- Filter todos by completion status
|
|
- Input validation with Pydantic
|
|
- Database migrations with Alembic
|
|
- Error handling and structured responses
|
|
- Health check endpoint
|
|
- API documentation with Swagger UI
|
|
|
|
## Technologies Used
|
|
|
|
- [FastAPI](https://fastapi.tiangolo.com/) - Modern web framework for building APIs
|
|
- [SQLAlchemy](https://www.sqlalchemy.org/) - SQL toolkit and ORM
|
|
- [Pydantic](https://docs.pydantic.dev/) - Data validation and settings management
|
|
- [Alembic](https://alembic.sqlalchemy.org/) - Database migration tool
|
|
- [SQLite](https://www.sqlite.org/) - File-based SQL database
|
|
- [Uvicorn](https://www.uvicorn.org/) - ASGI server
|
|
- [Ruff](https://beta.ruff.rs/docs/) - Python linter and formatter
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
todoapi/
|
|
├── alembic.ini # Alembic configuration
|
|
├── app/ # Application package
|
|
│ ├── api/ # API endpoints
|
|
│ │ ├── endpoints/ # Endpoint handlers
|
|
│ │ │ └── todos.py # Todo endpoints
|
|
│ │ ├── api.py # API router
|
|
│ │ └── errors.py # Error handling
|
|
│ ├── db/ # Database
|
|
│ │ └── database.py # Database configuration
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ │ └── todo.py # Todo model
|
|
│ └── schemas/ # Pydantic schemas
|
|
│ └── todo.py # Todo schemas
|
|
├── main.py # Application entry point
|
|
├── migrations/ # Database migrations
|
|
│ ├── env.py # Alembic environment
|
|
│ ├── script.py.mako # Migration template
|
|
│ └── versions/ # Migration scripts
|
|
├── pyproject.toml # Project configuration
|
|
└── requirements.txt # Dependencies
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /todos` - List all todo items (with optional filtering)
|
|
- `GET /todos/{todo_id}` - Get a specific todo item
|
|
- `POST /todos` - Create a new todo item
|
|
- `PUT /todos/{todo_id}` - Update a todo item
|
|
- `DELETE /todos/{todo_id}` - Delete a todo item
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.9 or higher
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository
|
|
2. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run the application:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
4. Visit the API documentation at http://localhost:8000/docs
|
|
|
|
## Database Migrations
|
|
|
|
The application uses Alembic for database migrations:
|
|
|
|
```bash
|
|
# Apply migrations
|
|
alembic upgrade head
|
|
|
|
# Create a new migration (after modifying models)
|
|
alembic revision --autogenerate -m "description"
|
|
```
|
|
|
|
## Development
|
|
|
|
To lint and format the code:
|
|
|
|
```bash
|
|
ruff check .
|
|
ruff check --fix .
|
|
``` |