Skip to content

Add /health endpoint for container health checks #346

@nanotaboada

Description

@nanotaboada

Description

Currently, the FastAPI app does not expose a dedicated /health endpoint for health checking. Adding this endpoint will improve container orchestration support (e.g., Docker, Kubernetes), enabling external systems to verify if the service is alive and responsive.

Suggested Approach

Implement a simple GET /health endpoint returning a JSON response such as {"status": "ok"} with HTTP status 200. This endpoint should be lightweight and not depend on external services to respond quickly.

Proposed Implementation

health_route.py

from fastapi import APIRouter


api_router = APIRouter()

@api_router.get("/health", tags=["Health"])
async def health_check():
    """
    Simple health check endpoint. Returns a JSON response with a single key "status" and value "ok".
    """
    return {"status": "ok"}

main.py

app.include_router(health_route.api_router)

healthcheck.sh

#!/bin/sh
set -e

# Simple health check using curl
curl --fail http://localhost:9000/health

Dockerfile

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
    CMD ["./healthcheck.sh"]

Acceptance Criteria

  • A /health endpoint is accessible and returns HTTP 200 with {"status": "ok"} JSON.
  • The endpoint responds quickly without depending on database or external services.
  • Automated tests cover the new endpoint.
  • Dockerfile includes a working HEALTHCHECK referencing the /health endpoint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomerspythonPull requests that update Python code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions