diff --git a/README.md b/README.md index 34a674d..bca9250 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Here is what you need to get started. ```python from fastapi import FastAPI from fastapi_healthcheck import HealthCheckFactory, healthCheckRoute +from fastapi_healthcheck.model import HealthCheckModel from fastapi_healthcheck_sqlalchemy import HealthCheckSQLAlchemy app = FastAPI() @@ -28,7 +29,7 @@ _healthChecks.add(HealthCheckSQLAlchemy(alias='postgres db', connectionUri=cs.va # This will check external URI and validate the response that is returned. # fastapi-healthcheck-uri _healthChecks.add(HealthCheckUri(alias='reddit', connectionUri="https://www.reddit.com/r/aww.json", tags=('external', 'reddit', 'aww'))) -app.add_api_route('/health', endpoint=healthCheckRoute(factory=_healthChecks)) +app.add_api_route('/health', endpoint=healthCheckRoute(factory=_healthChecks), response_model=HealthCheckModel) ``` diff --git a/fastapi_healthcheck/enum.py b/fastapi_healthcheck/enum.py index 3ee3ce1..1902769 100644 --- a/fastapi_healthcheck/enum.py +++ b/fastapi_healthcheck/enum.py @@ -2,5 +2,5 @@ class HealthCheckStatusEnum(Enum): - HEALTHY = "Healthy" - UNHEALTHY = "Unhealthy" + HEALTHY = "healthy" + UNHEALTHY = "unhealthy" diff --git a/fastapi_healthcheck/route.py b/fastapi_healthcheck/route.py index c816942..a340163 100644 --- a/fastapi_healthcheck/route.py +++ b/fastapi_healthcheck/route.py @@ -11,14 +11,16 @@ def healthCheckRoute(factory: HealthCheckFactory) -> Callable: When called, the endpoint method within, will be called and it will run the job bound to the factory. The results will be parsed and sent back to the requestor via JSON. """ - + _factory = factory def endpoint() -> JSONResponse: - res = _factory.check() - if res['status'] == HealthCheckStatusEnum.UNHEALTHY.value: - return JSONResponse(content=res, status_code=500) - return JSONResponse(content=res, status_code=200) + """ + Check health of API and associated services. + """ + res = _factory.check() + code = 500 if res["status"] == HealthCheckStatusEnum.UNHEALTHY.value else 200 + return JSONResponse(content=res, status_code=code) return endpoint