1.9 KiB
1.9 KiB
Simple Todo API
A simple Todo API built with FastAPI and SQLite.
Features
- CRUD operations for Todo items
- Filtering and pagination for todos list
- Health check endpoint
- OpenAPI documentation
Requirements
- Python 3.8+
- FastAPI
- SQLAlchemy
- Alembic
- SQLite
- Uvicorn
Installation
- Clone the repository:
git clone https://github.com/yourusername/simpletodoapi.git
cd simpletodoapi
- Install the dependencies:
pip install -r requirements.txt
- Apply migrations:
alembic upgrade head
Running the Application
Start the application with:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
Once the application is running, you can access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
API Endpoints
Todos
GET /api/todos
- List all todos with optional filtering and paginationPOST /api/todos
- Create a new todoGET /api/todos/{todo_id}
- Get a specific todoPUT /api/todos/{todo_id}
- Update a todoDELETE /api/todos/{todo_id}
- Delete a todo
Health
GET /health
- Check API health status
Examples
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
}'
List Todos
curl -X 'GET' 'http://localhost:8000/api/todos'
Get a specific Todo
curl -X 'GET' 'http://localhost:8000/api/todos/1'
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'
License
MIT