
- Fixed Python import path in alembic/env.py - Added settings import to ensure consistent database URL - Synchronized database configuration between app and alembic generated with BackendIM... (backend.im)
Simple Todo Application
A simple RESTful API for managing todos built with FastAPI, SQLAlchemy, and SQLite.
Features
- Create, Read, Update, Delete todo items
- Filter todos by completion status
- Proper error handling and validation
- API documentation via Swagger UI
- SQLite database for persistence
- Database migrations using Alembic
Project Structure
simpletodoapplication/
├── alembic/ # Database migration scripts
├── app/ # Application package
│ ├── api/ # API endpoints
│ │ └── routers/ # API routers
│ ├── core/ # Core functionality
│ ├── db/ # Database session and connection
│ ├── models/ # SQLAlchemy models
│ └── schemas/ # Pydantic schemas
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
Setup
- Clone the repository:
git clone <repository-url>
cd simpletodoapplication
- Install dependencies:
pip install -r requirements.txt
- Apply database migrations:
alembic upgrade head
- Run the application:
uvicorn main:app --reload
The API server will be running at http://localhost:8000.
API Documentation
Once the server is running, you can access the auto-generated API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
-
GET /api/v1/todos
: Get all todos- Query Parameters:
skip
: Number of items to skip (default: 0)limit
: Maximum number of items to return (default: 100)completed
: Filter by completion status (boolean, optional)
- Query Parameters:
-
POST /api/v1/todos
: Create a new todo- Request Body:
title
: String (required)description
: String (optional)completed
: Boolean (default: false)
- Request Body:
-
GET /api/v1/todos/{todo_id}
: Get a specific todo by ID -
PUT /api/v1/todos/{todo_id}
: Update a todo- Request Body (all fields optional):
title
: Stringdescription
: Stringcompleted
: Boolean
- Request Body (all fields optional):
-
DELETE /api/v1/todos/{todo_id}
: Delete a todo -
GET /health
: Health check endpoint
Example Requests
Create a Todo
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
curl -X 'GET' \
'http://localhost:8000/api/v1/todos/' \
-H 'accept: application/json'
Get Only Completed Todos
curl -X 'GET' \
'http://localhost:8000/api/v1/todos/?completed=true' \
-H 'accept: application/json'
Update a Todo
curl -X 'PUT' \
'http://localhost:8000/api/v1/todos/1' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"completed": true
}'
Delete a Todo
curl -X 'DELETE' \
'http://localhost:8000/api/v1/todos/1' \
-H 'accept: application/json'
Description
Languages
Python
96.2%
Mako
3.8%