todoapp-d7nzgy/main.py
Automated Action 29d1f9d0d1 Implement complete Todo API with CRUD endpoints
- Created FastAPI application with Todo CRUD operations
- Implemented GET /api/v1/todos/ for listing todos with pagination
- Implemented POST /api/v1/todos/ for creating new todos
- Implemented GET /api/v1/todos/{id} for retrieving specific todos
- Implemented PUT /api/v1/todos/{id} for updating todos
- Implemented DELETE /api/v1/todos/{id} for deleting todos
- Added proper error handling with 404 responses
- Configured SQLAlchemy with SQLite database
- Set up Alembic for database migrations
- Added Pydantic schemas for request/response validation
- Enabled CORS for all origins
- Added health check endpoint at /health
- Updated README with complete API documentation
2025-06-20 02:28:53 +00:00

52 lines
1.2 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.todos import router as todos_router
from app.db.base import Base
from app.db.session import engine
# Create database tables
Base.metadata.create_all(bind=engine)
app = FastAPI(
title="Todo API",
description="A simple Todo API built with FastAPI",
version="1.0.0",
openapi_url="/openapi.json"
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(todos_router, prefix="/api/v1")
@app.get("/")
def root():
"""
Root endpoint that returns basic information about the API.
"""
return {
"title": "Todo API",
"description": "A simple Todo API built with FastAPI",
"version": "1.0.0",
"documentation": "/docs",
"health_check": "/health"
}
@app.get("/health")
def health_check():
"""
Health check endpoint to verify the application is running.
"""
return {
"status": "healthy",
"message": "Todo API is running successfully"
}