
- 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)
2.3 KiB
2.3 KiB
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
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Running the application
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 endpointGET /api/todos
- Get all todos (with pagination)GET /api/todos/{todo_id}
- Get a specific todoPOST /api/todos
- Create a new todoPUT /api/todos/{todo_id}
- Update a todoDELETE /api/todos/{todo_id}
- Delete a todo
Example Requests
Create a Todo
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
curl -X 'GET' 'http://localhost:8000/api/todos/'
Update a Todo
curl -X 'PUT' \
'http://localhost:8000/api/todos/1' \
-H 'Content-Type: application/json' \
-d '{
"completed": true
}'
Delete a Todo
curl -X 'DELETE' 'http://localhost:8000/api/todos/1'