How do you know if your API is healthy? Database connected? Redis alive?
// Program.cs
builder.Services.AddHealthChecks()
.AddDbContextCheck()
.AddRedis("localhost:6379");
app.MapHealthChecks("/health");
// Visit /health
// Response: Healthy or Unhealthy + details
Custom Check:
public class ApiHealthCheck : IHealthCheck
{
public async Task CheckHealthAsync(...)
{
var isHealthy = await CheckExternalApiAsync();
return isHealthy
? HealthCheckResult.Healthy()
: HealthCheckResult.Unhealthy("API down");
}
}
Use With: Kubernetes liveness probes, monitoring tools.

