When the project is an API, it is required to implement a healthcheck
endpoint, it is recommended that
the project applies the defined standard of the guideline documentation, so that it is an intelligent endpoint.
Your API needs to have an endpoint so that service validation tools can ensure that a service is available.
Considering that we have a service that has the following characteristics:
- Reading files from an AWS bucket;
- Connection to a database;
- Consumption of two external APIs.
Below are some code examples of what a return from this type of endpoint should look like:
HTTP Status 200 OK
{
"status": "healthy",
"totalDuration": "00:00:00.00800",
"entries": {
"self": {
"status": "healthy",
"duration": "00:00:00.00100",
"tags": []
},
"aws": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"s3"
]
},
"db": {
"status": "healthy",
"duration": "00:00:00.00100",
"tags": [
"db"
]
},
"queue-service": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"api"
]
},
"product-service": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"api"
]
}
}
}
HTTP Status 424 Failed dependecy
{
"status": "unhealthy",
"totalDuration": "00:00:00.10000",
"entries": {
"self": {
"status": "healthy",
"duration": "00:00:00.00100",
"tags": []
},
"aws": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"s3"
]
},
"db": {
"status": "healthy",
"duration": "00:00:00.00100",
"tags": [
"db"
]
},
"queue-service": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"api"
]
},
"product-service": {
"status": "unhealthy",
"duration": "00:00:00.00500",
"tags": [
"api"
]
}
}
}
HTTP Status 500 Internal Server Error
{
"status": "unhealthy",
"totalDuration": "00:00:00.10000",
"entries": {
"self": {
"status": "unhealthy",
"duration": "00:00:00.00100",
"tags": []
},
"aws": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"s3"
]
},
"db": {
"status": "unhealthy",
"duration": "00:00:00.00500",
"tags": [
"db"
]
},
"queue-service": {
"status": "healthy",
"duration": "00:00:00.00200",
"tags": [
"api"
]
},
"product-service": {
"status": "unhealthy",
"duration": "00:00:00.00500",
"tags": [
"api"
]
}
}
}