What HTTP status code does the health check middleware return by default for each status (Healthy, Degraded, Unhealthy)?
Short answer
By default, HealthStatus.Healthy and HealthStatus.Degraded both map to a 200 OK response, while HealthStatus.Unhealthy maps to a 503 Service Unavailable response -- this default mapping can be customized via HealthCheckOptions.ResultStatusCodes if a different status code scheme…
Advertisement
AModel answer
By default, HealthStatus.Healthy and HealthStatus.Degraded both map to a 200 OK response, while HealthStatus.Unhealthy maps to a 503 Service Unavailable response -- this default mapping can be customized via HealthCheckOptions.ResultStatusCodes if a different status code scheme is needed, but the built-in defaults are designed so load balancers and orchestrators can rely on a simple 200-versus-503 distinction without needing to parse a response body.
app.MapHealthChecks("/health", new HealthCheckOptions {
ResultStatusCodes = {
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Degraded] = StatusCodes.Status200OK,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
}
});Real-world example
A load balancer configured to simply check for a 200 status code from /health automatically stops routing traffic to an instance once its status turns Unhealthy and the endpoint starts returning 503, without needing any custom logic to parse a JSON response body.
Likely follow-ups
- Why might you want Degraded to also return a non-200 status in some scenarios?
- How do downstream consumers typically differentiate their response to a 503 versus inspecting a detailed JSON body?
Related topics