
- Add CRUD operations for todos (create, read, update, delete) - Implement SQLAlchemy models and schemas - Set up Alembic for database migrations - Add health endpoint and CORS configuration - Include comprehensive API documentation - Structure project with proper separation of concerns
39 lines
909 B
Python
39 lines
909 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.routes import todos_router
|
|
from app.db.base import Base
|
|
from app.db.session import engine
|
|
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="Todo App API",
|
|
description="A simple Todo application API built with FastAPI",
|
|
version="1.0.0",
|
|
openapi_url="/openapi.json"
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(todos_router, prefix="/todos", tags=["todos"])
|
|
|
|
|
|
@app.get("/")
|
|
def root():
|
|
return {
|
|
"title": "Todo App API",
|
|
"description": "A simple Todo application API built with FastAPI",
|
|
"documentation": "/docs",
|
|
"health": "/health"
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
def health_check():
|
|
return {"status": "healthy", "service": "todo-app"} |