Skip to content

Commit

Permalink
add health endpoint to the service API (#4)
Browse files Browse the repository at this point in the history
* microservice template update

* update readme, fix ruff failures

* fix mypy errors

* add health endpoint to the service API
  • Loading branch information
dontseyit authored Oct 11, 2023
1 parent c40eba0 commit a9781dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ info:
version: 0.1.0
openapi: 3.0.2
paths:
/health:
get:
description: Used to test if this service is alive
operationId: health_health_get
responses:
'200':
content:
application/json:
schema: {}
description: Successful Response
summary: health
/values:
get:
description: Retrieves all values from the WellKnownsConfig class
Expand Down
10 changes: 10 additions & 0 deletions src/wkvs/adapters/inbound/fastapi_/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
router = APIRouter()


@router.get(
"/health",
summary="health",
status_code=status.HTTP_200_OK,
)
async def health():
"""Used to test if this service is alive"""
return {"status": "OK"}


@router.get(
"/values/{value_name}",
summary="retrieve a configured value",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
from tests.fixtures.joint import JointFixture, joint_fixture # noqa: F401


@pytest.mark.asyncio
async def test_health_check(joint_fixture: JointFixture): # noqa: F811
"""Test that the health check endpoint works."""
response = await joint_fixture.rest_client.get("/health")

assert response.status_code == 200
assert response.json() == {"status": "OK"}


@pytest.mark.asyncio
async def test_happy_retrieval(joint_fixture: JointFixture): # noqa: F811
"""Test that configured values can be retrieved"""
Expand Down

0 comments on commit a9781dd

Please sign in to comment.