Automated Action bf1393d643 Create Simple Todo API with FastAPI and SQLite
- Set up FastAPI project structure
- Configure SQLAlchemy with SQLite
- Create Todo model and schemas
- Implement CRUD operations
- Add API endpoints for Todo management
- Configure Alembic for database migrations
- Add health check endpoint
- Add comprehensive documentation
2025-05-17 20:16:30 +00:00

26 lines
747 B
Python

from fastapi import APIRouter, Depends, status
from sqlalchemy.orm import Session
from app.db.session import get_db
router = APIRouter()
@router.get("/health", status_code=status.HTTP_200_OK)
def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint to verify API is running and database is accessible
"""
try:
# Execute a simple query to check if database is accessible
db.execute("SELECT 1")
return {
"status": "healthy",
"message": "API is running and database is accessible",
}
except Exception as e:
return {
"status": "unhealthy",
"message": f"API is running but database is not accessible: {str(e)}",
}