
- Set up project structure - Create database models with SQLAlchemy - Add Alembic migrations - Implement CRUD API endpoints - Update README with documentation generated with BackendIM... (backend.im)
113 lines
2.3 KiB
Markdown
113 lines
2.3 KiB
Markdown
# SimpleTodoApp
|
|
|
|
A simple Todo application API built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todo items
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic migrations for database versioning
|
|
- RESTful API with proper HTTP methods and status codes
|
|
- Health check endpoint
|
|
- Documentation with Swagger UI and ReDoc
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
simpletodoapp/
|
|
├── alembic.ini
|
|
├── app/
|
|
│ ├── __init__.py
|
|
│ ├── api/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todos.py
|
|
│ ├── crud/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todo.py
|
|
│ ├── db/
|
|
│ │ ├── __init__.py
|
|
│ │ └── database.py
|
|
│ ├── models/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todo.py
|
|
│ └── schemas/
|
|
│ ├── __init__.py
|
|
│ └── todo.py
|
|
├── main.py
|
|
├── migrations/
|
|
│ ├── README
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ └── versions/
|
|
│ └── a7d956f83192_create_todos_table.py
|
|
└── requirements.txt
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository
|
|
2. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Running the application
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000
|
|
|
|
## API Documentation
|
|
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /api/todos` - Get all todos (with pagination)
|
|
- `GET /api/todos/{todo_id}` - Get a specific todo
|
|
- `POST /api/todos` - Create a new todo
|
|
- `PUT /api/todos/{todo_id}` - Update a todo
|
|
- `DELETE /api/todos/{todo_id}` - Delete a todo
|
|
|
|
## Example Requests
|
|
|
|
### Create a Todo
|
|
|
|
```bash
|
|
curl -X 'POST' \
|
|
'http://localhost:8000/api/todos/' \
|
|
-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/todos/'
|
|
```
|
|
|
|
### Update a Todo
|
|
|
|
```bash
|
|
curl -X 'PUT' \
|
|
'http://localhost:8000/api/todos/1' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"completed": true
|
|
}'
|
|
```
|
|
|
|
### Delete a Todo
|
|
|
|
```bash
|
|
curl -X 'DELETE' 'http://localhost:8000/api/todos/1'
|
|
``` |