
- Implement Todo database model with SQLAlchemy - Set up Alembic for database migrations - Create CRUD operations for Todo items - Implement RESTful API endpoints - Add health check endpoint - Include comprehensive README with usage instructions
36 lines
873 B
Python
36 lines
873 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
|
|
from app.database import init_db
|
|
from app.routers import todos, health
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Initialize database
|
|
init_db()
|
|
yield
|
|
|
|
app = FastAPI(
|
|
title="SimpleTodoApp",
|
|
description="A simple Todo application API built with FastAPI",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# 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", tags=["todos"])
|
|
app.include_router(health.router, tags=["health"])
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |