Automated Action f2d3f2d55c Create FastAPI REST API with Python and SQLite
- Implemented user authentication with JWT
- Added CRUD operations for users and items
- Setup database connection with SQLAlchemy
- Added migration scripts for easy database setup
- Included health check endpoint for monitoring

generated with BackendIM... (backend.im)
2025-05-13 18:33:54 +00:00

28 lines
672 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from datetime import datetime
from app.database import get_db
router = APIRouter()
@router.get("/health", tags=["health"])
def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint to verify API status
"""
# Test 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": "ok",
"timestamp": datetime.now().isoformat(),
"database": db_status,
"version": "0.1.0"
}