Automated Action 07301a47e7 Implement RESTful API using FastAPI and SQLite
- Set up project structure with FastAPI framework
- Implement database models using SQLAlchemy
- Create Alembic migrations for database schema
- Build CRUD endpoints for Items resource
- Add health check endpoint
- Include API documentation with Swagger and ReDoc
- Update README with project documentation
2025-05-18 16:46:51 +00:00

39 lines
829 B
Python

from fastapi import APIRouter, Depends, status
from pydantic import BaseModel
from sqlalchemy.orm import Session
from app.db.database import get_db
router = APIRouter()
class HealthCheck(BaseModel):
status: str
api_version: str
db_status: str
@router.get(
"/",
response_model=HealthCheck,
status_code=status.HTTP_200_OK,
description="Health check for the API"
)
def health_check(db: Session = Depends(get_db)):
"""
Perform a health check for the API
"""
db_status = "healthy"
# Simple DB connection check
try:
# Execute a simple query to check DB connection
db.execute("SELECT 1")
except Exception:
db_status = "unhealthy"
return {
"status": "healthy",
"api_version": "1.0.0",
"db_status": db_status
}