A health-check or simply health endpoint can be very useful for testing and inspecting a running API, especially when rather implementation-specific information is used. It can also be used as the endpoint called by automated monitoring and alerting.
For a microservice, the health often depends on several dependencies. The health endpoint can list the status of the dependencies.
An example call:
Some other options for naming: “status”, or “isHealthy”.
The response status code is 200 OK for a healthy API, and a good choice for unhealthy is 503 Service Unavailable.
Getting more specific, we can design sub-resources for health information pertaining to subdomains or functionality of the API.
For a concrete example, imagine an API which can report on the status of a data ingest service as part of its own health:
This sub-resource gives us specific information about a data ingest subsystem.
We can use this sort of design to make monitoring more granular: imagine an alert being fired only when certain specific health sub-resources return an error status, but not all.
Using Headers for Health Status
Another option is to use HTTP headers for specific details and keep the JSON result body small, showing only the status. For example: