todoapp-dkaeyp/README.md
2025-05-26 17:55:11 +00:00

135 lines
3.4 KiB
Markdown

# 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:
```bash
git clone <repository-url>
cd todoapp
```
2. Install the required packages:
```bash
pip install -r requirements.txt
```
3. Run the database migrations:
```bash
alembic upgrade head
```
4. Start the application:
```bash
uvicorn main:app --reload
```
5. The API will be available at http://localhost:8000
- API documentation: http://localhost:8000/docs
- Alternative documentation: http://localhost:8000/redoc
## 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:
```json
{
"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):
```json
{
"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:
```bash
alembic revision --autogenerate -m "description of changes"
alembic upgrade head
```
### Running Tests
Tests can be run using pytest:
```bash
pytest
```
## License
This project is licensed under the MIT License.