2025-06-10 15:58:25 +00:00

139 lines
2.6 KiB
Markdown

# Simple Todo App
A simple REST API for managing todo items, built with FastAPI and SQLite.
## Features
- Create, read, update, and delete todo items
- SQLite database with SQLAlchemy ORM
- Alembic for database migrations
- Health check endpoint
- API documentation
## Requirements
- Python 3.8+
- FastAPI
- SQLAlchemy
- Alembic
- Uvicorn
- SQLite
## Setup
1. Clone the repository:
```bash
git clone https://github.com/yourusername/simpletodoapp.git
cd simpletodoapp
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run database migrations:
```bash
alembic upgrade head
```
4. Start the server:
```bash
uvicorn main:app --reload
```
The API will be available at http://localhost:8000
## API Documentation
API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## API Endpoints
### Root
- `GET /` - Returns basic app information
### Health Check
- `GET /health` - Returns the health status of the API
### Todo Operations
- `GET /api/v1/todos` - Get all todos
- `POST /api/v1/todos` - Create a new todo
- `GET /api/v1/todos/{todo_id}` - Get a specific todo
- `PUT /api/v1/todos/{todo_id}` - Update a todo
- `DELETE /api/v1/todos/{todo_id}` - Delete a todo
## Example Usage
### Create a Todo
```bash
curl -X 'POST' \
'http://localhost:8000/api/v1/todos/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, eggs, bread",
"completed": false
}'
```
### Get All Todos
```bash
curl -X 'GET' \
'http://localhost:8000/api/v1/todos/' \
-H 'accept: application/json'
```
### Mark Todo as Completed
```bash
curl -X 'PUT' \
'http://localhost:8000/api/v1/todos/1' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"completed": true
}'
```
## Project Structure
```
simpletodoapp/
├── app/
│ ├── api/
│ │ └── api_v1/
│ │ ├── endpoints/
│ │ │ └── todos.py
│ │ └── api.py
│ ├── core/
│ │ └── config.py
│ ├── crud/
│ │ ├── base.py
│ │ └── todo.py
│ ├── db/
│ │ ├── base.py
│ │ ├── base_class.py
│ │ └── session.py
│ ├── models/
│ │ └── todo.py
│ └── schemas/
│ └── todo.py
├── migrations/
│ └── versions/
│ └── 001_create_todos_table.py
├── storage/
│ └── db/
│ └── db.sqlite
├── alembic.ini
├── main.py
└── requirements.txt
```