
- Set up project structure - Create FastAPI app with health endpoint - Implement SQLAlchemy with SQLite database - Set up Alembic for database migrations - Create CRUD operations for items - Add comprehensive documentation
25 lines
656 B
Python
25 lines
656 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.db.session import get_db
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", summary="Health check endpoint")
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint to verify that the API is running and can connect to the database.
|
|
|
|
Returns:
|
|
dict: A JSON object with the status of the service and database connection
|
|
"""
|
|
db_status = "healthy"
|
|
try:
|
|
# Try to execute a simple query
|
|
db.execute("SELECT 1")
|
|
except Exception:
|
|
db_status = "unhealthy"
|
|
|
|
return {"status": "ok", "database": db_status}
|