We just had a similar discussion in our group. For our purposes, we decided that HTTP response codes should report the success of your server or not fulfill this request. For GET, this means that you can respond with the requested resource. In this case, the requested resource is a health report, so while you return it successfully, it should be 200 response.
We return JSON for health checks, with the top-level "isHealthy" field set to true or false. Our load balancer and other monitors will analyze JSON and use this field to determine if the system is healthy or not.
If you do not want to parse JSON in your monitors, you can try placing a custom response header to indicate the binary state of the system, for example, System-Health: true or System-Health: false . You may be lucky to see monitors that can verify this.
If you really want to use a response code, I would recommend an additional endpoint called "health", which returns "204 No Content" when it is healthy, and "404 Not Found" when it is not healthy. In this case, the resource identified by the URL is symbolically the health of your system, so if it is healthy, you can return a successful response. If it is unhealthy, then this health cannot be found, therefore, 404.
source share