
- Set up FastAPI project structure with best practices - Implemented SQLAlchemy models with SQLite database - Added Alembic for database migrations - Created CRUD API endpoints for items - Added health check endpoint - Updated documentation generated with BackendIM... (backend.im)
29 lines
759 B
Python
29 lines
759 B
Python
from fastapi import APIRouter, Depends, status
|
|
from sqlalchemy.orm import Session
|
|
from app.core.database import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/health", status_code=status.HTTP_200_OK, tags=["Health"])
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Check the health of the API.
|
|
|
|
Returns:
|
|
dict: Status information about the API and its dependencies
|
|
"""
|
|
# Check database connection
|
|
try:
|
|
# Just execute a simple query
|
|
db.execute("SELECT 1")
|
|
db_status = "healthy"
|
|
except Exception as e:
|
|
db_status = f"unhealthy: {str(e)}"
|
|
|
|
return {
|
|
"status": "online",
|
|
"api_version": "1.0",
|
|
"dependencies": {
|
|
"database": db_status
|
|
}
|
|
} |