Automated Action 9c5b74200b Setup basic FastAPI project with Todo API
- Created requirements.txt with necessary dependencies
- Set up FastAPI application structure with main.py
- Added health endpoint
- Configured SQLAlchemy with SQLite database
- Initialized Alembic for database migrations
- Created Todo model and API endpoints
- Updated README with setup and usage instructions
- Linted code with Ruff
2025-05-29 02:07:19 +00:00

2.7 KiB

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

  1. Clone the repository
  2. Install the dependencies:
    pip install -r requirements.txt
    
  3. Run the database migrations:
    alembic upgrade head
    
  4. Start the API server:
    uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    

API Endpoints

  • GET /: Root endpoint with welcome message
  • GET /health: Health check endpoint
  • GET /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 items
  • GET /todos/{todo_id}: Get a specific todo item
  • POST /todos: Create a new todo item
  • PUT /todos/{todo_id}: Update a todo item
  • DELETE /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 Key
  • title: String, Not Null
  • description: String, Nullable
  • completed: Boolean, Default: False
  • created_at: DateTime, Default: Current Timestamp
  • updated_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.