Automated Action 00174fd9dc Create REST API with FastAPI and SQLite
- Set up project structure with FastAPI
- Configure SQLite database with SQLAlchemy
- Set up Alembic for migrations
- Create Item model and schema
- Implement CRUD operations
- Add health endpoint

generated with BackendIM... (backend.im)
2025-05-13 21:57:29 +00:00

28 lines
695 B
Python

from typing import Dict
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.api import deps
from app.db.session import engine
router = APIRouter()
@router.get("/", response_model=Dict[str, str])
def health_check(db: Session = Depends(deps.get_db)) -> Dict[str, str]:
"""
Health check endpoint to verify API is running and database connection is working.
"""
try:
# Test database connection
with engine.connect() as connection:
connection.execute("SELECT 1")
db_status = "healthy"
except Exception:
db_status = "unhealthy"
return {
"status": "up",
"database": db_status
}