
- 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)
22 lines
576 B
Python
22 lines
576 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.db.database import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/")
|
|
async def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint to verify the API is running and can connect to the database.
|
|
"""
|
|
try:
|
|
# Execute a simple query to check database connection
|
|
db.execute("SELECT 1")
|
|
db_status = "healthy"
|
|
except Exception:
|
|
db_status = "unhealthy"
|
|
|
|
return {
|
|
"status": "healthy",
|
|
"database": db_status
|
|
} |