Todo List API
A simple Todo List API built with FastAPI and SQLite. This API allows you to create, read, update, and delete todo items.
Features
- RESTful API with CRUD operations for todo items
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Auto-generated API documentation with Swagger UI and ReDoc
- Health check endpoint
- Code linting with Ruff
Requirements
- Python 3.8+
- FastAPI
- SQLAlchemy
- Alembic
- Uvicorn
- SQLite
Setup
- Clone the repository
- Install the dependencies:
pip install -r requirements.txt
- Run the database migrations:
alembic upgrade head
- Start the API server:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
API Endpoints
GET /
: Root endpoint with welcome messageGET /health
: Health check endpointGET /docs
: Auto-generated API documentation (Swagger UI)GET /redoc
: Alternative API documentation (ReDoc)GET /openapi.json
: OpenAPI schema
Todo Endpoints
GET /todos
: Get all todo itemsGET /todos/{todo_id}
: Get a specific todo itemPOST /todos
: Create a new todo itemPUT /todos/{todo_id}
: Update a todo itemDELETE /todos/{todo_id}
: Delete a todo item
API Usage Examples
Create a Todo Item
curl -X 'POST' \
'http://localhost:8000/todos' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, eggs, bread",
"completed": false
}'
Get All Todo Items
curl -X 'GET' 'http://localhost:8000/todos'
Get a Specific Todo Item
curl -X 'GET' 'http://localhost:8000/todos/1'
Update a Todo Item
curl -X 'PUT' \
'http://localhost:8000/todos/1' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, eggs, bread, cheese",
"completed": true
}'
Delete a Todo Item
curl -X 'DELETE' 'http://localhost:8000/todos/1'
Database Schema
The database schema consists of a single todos
table with the following columns:
id
: Integer, Primary Keytitle
: String, Not Nulldescription
: String, Nullablecompleted
: Boolean, Default: Falsecreated_at
: DateTime, Default: Current Timestampupdated_at
: DateTime, Nullable
Development
For local development, you can use the following commands:
-
Start the application with auto-reload:
uvicorn main:app --reload
-
Run Ruff for linting:
ruff check .
-
Run Ruff for auto-fix:
ruff check --fix .
-
Create a new migration:
alembic revision -m "Your migration message"
-
Run migrations:
alembic upgrade head
License
This project is licensed under the MIT License.
Description
Languages
Python
97.2%
Mako
2.8%