NetEvolve.HealthChecks.Http
5.8.0
Prefix Reserved
See the version list below for details.
dotnet add package NetEvolve.HealthChecks.Http --version 5.8.0
NuGet\Install-Package NetEvolve.HealthChecks.Http -Version 5.8.0
<PackageReference Include="NetEvolve.HealthChecks.Http" Version="5.8.0" />
<PackageVersion Include="NetEvolve.HealthChecks.Http" Version="5.8.0" />
<PackageReference Include="NetEvolve.HealthChecks.Http" />
paket add NetEvolve.HealthChecks.Http --version 5.8.0
#r "nuget: NetEvolve.HealthChecks.Http, 5.8.0"
#:package NetEvolve.HealthChecks.Http@5.8.0
#addin nuget:?package=NetEvolve.HealthChecks.Http&version=5.8.0
#tool nuget:?package=NetEvolve.HealthChecks.Http&version=5.8.0
NetEvolve.HealthChecks.Http
This package contains a health check for HTTP endpoints, based on the HttpClient.
The health check verifies that HTTP endpoints respond with expected status codes within a configured timeout.
💡 This package is available for .NET 8.0 and later.
Installation
To use this package, you need to add the package to your project. You can do this by using the NuGet package manager or by using the dotnet CLI.
dotnet add package NetEvolve.HealthChecks.Http
Health Check - HTTP Endpoint Liveness
The health check is a liveness check that verifies an HTTP endpoint is reachable and responds with expected status codes.
If the endpoint takes longer than the configured timeout to respond, the health check will return Degraded.
If the endpoint is not reachable or returns an unexpected status code, the health check will return Unhealthy.
Usage
After adding the package, you need to import the namespace NetEvolve.HealthChecks.Http and add the health check to the service collection.
using NetEvolve.HealthChecks.Http;
You can use two different approaches to add the health check. In both approaches you have to provide a name for the health check.
Parameters
name: The name of the health check. The name is used to identify the configuration object. It is required and must be unique within the application.options: The configuration options for the health check. If you don't provide any options, the health check will use the configuration based approach.tags: The tags for the health check. The tagshttpandendpointare always used as default and combined with the user input. You can provide additional tags to group or filter the health checks.
Variant 1: Configuration based
The first one is to use the configuration based approach. Therefore, you have to add the configuration section HealthChecks:Http to your appsettings.json file.
var builder = services.AddHealthChecks();
builder.AddHttp("<name>");
The configuration looks like this:
{
..., // other configuration
"HealthChecks": {
"Http": {
"<name>": {
"Uri": "<endpoint-uri>", // required
"HttpMethod": "<http-method>", // optional, default is "GET"
"ExpectedHttpStatusCodes": [200, 201], // optional, default is [200]
"Headers": { // optional, default is empty
"Authorization": "Bearer <token>",
"User-Agent": "HealthCheck/1.0"
},
"KeyedService": "<key>", // optional, must be given if you want to access a keyed service
"Timeout": "<timeout-in-ms>", // optional, default is 5000 milliseconds
"Content": "<request-body>", // optional, default is null
"ContentType": "<content-type>", // optional, default is "application/json"
"AllowAutoRedirect": true // optional, default is true
}
}
}
}
Variant 2: Builder based
The second approach is to use the builder based approach. This approach is recommended if you only have one HTTP endpoint to check or dynamic programmatic values.
var builder = services.AddHealthChecks();
builder.AddHttp("<name>", options =>
{
options.Uri = "<endpoint-uri>"; // required
options.HttpMethod = "<http-method>"; // optional, default is "GET"
options.ExpectedHttpStatusCodes = [200, 201]; // optional, default is [200]
options.Headers["Authorization"] = "Bearer <token>"; // optional
options.KeyedService = "<key>"; // optional, must be given if you want to access a keyed service
options.Timeout = 3000; // optional, default is 5000 milliseconds
options.Content = "<request-body>"; // optional, default is null
options.ContentType = "application/json"; // optional, default is "application/json"
options.AllowAutoRedirect = true; // optional, default is true
});
💡 You can always provide tags to all health checks, for grouping or filtering.
var builder = services.AddHealthChecks();
builder.AddHttp("<name>", options => ..., "http", "api");
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- NetEvolve.Extensions.Tasks (>= 2.0.11)
-
net8.0
- Microsoft.Extensions.Http (>= 10.0.0)
- NetEvolve.Extensions.Tasks (>= 2.0.11)
-
net9.0
- Microsoft.Extensions.Http (>= 10.0.0)
- NetEvolve.Extensions.Tasks (>= 2.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.