2.3 KiB
2.3 KiB
Todo Application API
This is a FastAPI-based Todo Application API that allows you to manage todo items. It's built with FastAPI and SQLite for data persistence.
Features
- Create, read, update, and delete todo items
- Filter todos by completion status
- Health check endpoint
- Swagger/OpenAPI documentation
- SQLite database with Alembic migrations
Tech Stack
- FastAPI: Modern, fast web framework for building APIs
- SQLAlchemy: SQL toolkit and Object-Relational Mapping
- Alembic: Database migration tool
- SQLite: Lightweight disk-based database
- Pydantic: Data validation and settings management
- Uvicorn: ASGI server for FastAPI
Setup
-
Clone the repository:
git clone [your-repository-url] cd todoapplication-omxawp
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn main:app --reload
-
Access the API:
- API: http://127.0.0.1:8000/
- Swagger docs: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
API Endpoints
Health Check
GET /health
- Check if the API is running
Todo Operations
POST /api/todos/
- Create a new todoGET /api/todos/
- List all todos (with optional filters)GET /api/todos/{todo_id}
- Get a specific todoPUT /api/todos/{todo_id}
- Update a todoDELETE /api/todos/{todo_id}
- Delete a todo
Example API Usage
Create a Todo Item
curl -X 'POST' \
'http://127.0.0.1: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://127.0.0.1:8000/api/todos/'
Get a Specific Todo
curl -X 'GET' 'http://127.0.0.1:8000/api/todos/1'
Update a Todo
curl -X 'PUT' \
'http://127.0.0.1:8000/api/todos/1' \
-H 'Content-Type: application/json' \
-d '{
"completed": true
}'
Delete a Todo
curl -X 'DELETE' 'http://127.0.0.1:8000/api/todos/1'
Database
The application uses SQLite with the database file stored at /app/storage/db/db.sqlite
.
Migrations
Migrations are handled with Alembic:
# Apply migrations
alembic upgrade head
# Create a new migration
alembic revision --autogenerate -m "Description of changes"