
- Set up project structure with proper directory layout - Implemented SQLite database with SQLAlchemy ORM - Created Todo model with CRUD operations - Added Alembic for database migrations - Implemented RESTful API endpoints for todos - Added health check endpoint - Configured CORS for all origins - Created comprehensive documentation - Added linting with Ruff
93 lines
2.2 KiB
Markdown
93 lines
2.2 KiB
Markdown
# Todo API
|
|
|
|
A simple Todo application API built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todos
|
|
- RESTful API endpoints
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- Health check endpoint
|
|
- CORS enabled for all origins
|
|
- Interactive API documentation
|
|
|
|
## Requirements
|
|
|
|
- Python 3.7+
|
|
- FastAPI
|
|
- SQLAlchemy
|
|
- Alembic
|
|
- Uvicorn
|
|
|
|
## Installation
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
3. Start the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at `http://localhost:8000`
|
|
|
|
## API Endpoints
|
|
|
|
### Base
|
|
- `GET /` - API information and links to documentation
|
|
|
|
### Health Check
|
|
- `GET /health` - Health check endpoint
|
|
|
|
### Todos
|
|
- `GET /api/v1/todos` - Get all todos (with pagination)
|
|
- `POST /api/v1/todos` - Create a new todo
|
|
- `GET /api/v1/todos/{id}` - Get a specific todo
|
|
- `PUT /api/v1/todos/{id}` - Update a todo
|
|
- `DELETE /api/v1/todos/{id}` - Delete a todo
|
|
|
|
## Documentation
|
|
|
|
- Interactive API docs: `http://localhost:8000/docs`
|
|
- ReDoc documentation: `http://localhost:8000/redoc`
|
|
- OpenAPI JSON: `http://localhost:8000/openapi.json`
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── main.py # FastAPI application entry point
|
|
├── requirements.txt # Python dependencies
|
|
├── alembic.ini # Alembic configuration
|
|
├── alembic/ # Database migrations
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ └── versions/
|
|
│ └── 0001_create_todos_table.py
|
|
└── app/
|
|
├── __init__.py
|
|
├── db/
|
|
│ ├── __init__.py
|
|
│ ├── base.py # SQLAlchemy declarative base
|
|
│ └── session.py # Database session configuration
|
|
├── models/
|
|
│ ├── __init__.py
|
|
│ └── todo.py # Todo model
|
|
└── routes/
|
|
├── __init__.py
|
|
├── todos.py # Todo CRUD endpoints
|
|
└── health.py # Health check endpoint
|
|
```
|
|
|
|
## Database
|
|
|
|
The application uses SQLite database stored at `/app/storage/db/db.sqlite`. The database is automatically created when the application starts.
|