
- Set up project structure with FastAPI - Create Todo database model and schema - Implement database connection with SQLAlchemy - Set up Alembic migrations - Implement CRUD API endpoints for Todo items - Add health check endpoint - Update documentation in README.md generated with BackendIM... (backend.im)
35 lines
944 B
Python
35 lines
944 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from pathlib import Path
|
|
|
|
from app.db.database import create_db_and_tables
|
|
from app.api.todos import router as todos_router
|
|
from app.api.health import router as health_router
|
|
|
|
app = FastAPI(
|
|
title="Todo Application API",
|
|
description="A simple Todo application API built with FastAPI",
|
|
version="0.1.0"
|
|
)
|
|
|
|
# Add CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(todos_router, prefix="/todos", tags=["todos"])
|
|
app.include_router(health_router, prefix="/health", tags=["health"])
|
|
|
|
@app.on_event("startup")
|
|
async def startup():
|
|
# Create database tables on startup
|
|
create_db_and_tables()
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |