
- Setup FastAPI project structure with main.py and requirements.txt - Implement SQLAlchemy ORM with SQLite database - Create Item model with CRUD operations - Implement health endpoint for monitoring - Setup Alembic for database migrations - Add comprehensive documentation in README.md - Configure Ruff for code linting
31 lines
702 B
Python
31 lines
702 B
Python
from datetime import datetime
|
|
|
|
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)):
|
|
"""
|
|
Check the health of the API.
|
|
|
|
Returns:
|
|
dict: Health status information including uptime and database status
|
|
"""
|
|
db_status = "ok"
|
|
try:
|
|
# Test database connection
|
|
db.execute("SELECT 1")
|
|
except Exception as e:
|
|
db_status = f"error: {str(e)}"
|
|
|
|
return {
|
|
"status": "ok",
|
|
"timestamp": datetime.utcnow().isoformat(),
|
|
"database": db_status,
|
|
}
|