CSharpEssentials.HttpHelper
2.0.1
See the version list below for details.
dotnet add package CSharpEssentials.HttpHelper --version 2.0.1
NuGet\Install-Package CSharpEssentials.HttpHelper -Version 2.0.1
<PackageReference Include="CSharpEssentials.HttpHelper" Version="2.0.1" />
<PackageVersion Include="CSharpEssentials.HttpHelper" Version="2.0.1" />
<PackageReference Include="CSharpEssentials.HttpHelper" />
paket add CSharpEssentials.HttpHelper --version 2.0.1
#r "nuget: CSharpEssentials.HttpHelper, 2.0.1"
#:package CSharpEssentials.HttpHelper@2.0.1
#addin nuget:?package=CSharpEssentials.HttpHelper&version=2.0.1
#tool nuget:?package=CSharpEssentials.HttpHelper&version=2.0.1
๐ CSharpEssentials.HttpHelper
A powerful and fluent HTTP helper for .NET built on top of HttpClientFactory, designed to simplify REST API calls with built-in support for retry policies, rate limiting, logging, timeouts, and dynamic configuration from appsettings.
๐ Features
โ
Fully configurable via appsettings.httpHelper.json
โ
Integrated with HttpClientFactory
โ
Automatic retry with Polly
โ
Rate Limiting using SlidingWindowRateLimiter
โ
Support for FormUrlEncodedContent and JSON
โ
Custom event-based logging
โ
Fluent API: .addTimeout(), .addRetryCondition(), .addHeaders(), etc.
๐ ๏ธ Setup
1. In Program.cs:
builder.Services.AddHttpClients(builder.Configuration);
2. Create or extend appsettings.httpHelper.json:
{
"HttpClientOptions": [
{
"Name": "Test1",
"RateLimitOptions": {
"AutoReplenishment": true,
"PermitLimit": 1,
"QueueLimit": 0,
"Window": "00:00:15",
"SegmentsPerWindow": 1
}
}
]
}
๐งฉ Usage Example
var httpsClientHelper = (httpsClientHelper)factory.CreateOrGet("Test1");
var response = await httpsClientHelper
.addTimeout(TimeSpan.FromSeconds(30))
.AddRequestAction(async (req, res, retry, ts) => {
Console.WriteLine($"[{req.Method}] {req.RequestUri} โ {(int)res.StatusCode} | RETRY: {retry} | RL Wait: {ts}");
})
.addRetryCondition(
res => res.StatusCode != HttpStatusCode.OK,
retryCount: 3,
backoffFactor: 2
)
.SendAsync(
"https://example.com/api",
HttpMethod.Get,
null,
new NoBodyContentBuilder()
);
string body = await response.Content.ReadAsStringAsync();
๐ก Auto-generated Headers
| Header | Description |
|---|---|
X-Retry-Attempt |
Number of retries attempted |
X-RateLimit-TimeSpanElapsed |
Elapsed wait time due to rate limiter (if any) |
โ๏ธ Fluent Extensions
httpsClientHelper
.addTimeout(TimeSpan.FromSeconds(15))
.addHeaders("Authorization", "Bearer your-token")
.addFormData(new List<KeyValuePair<string, string>> { ... })
.addRetryCondition(...)
.AddRequestAction(...);
๐งช Rate Limit Testing
To test rate limiting, trigger multiple concurrent calls using the same configured client (e.g., "Test1") and observe how the helper handles the cooldown period automatically using SlidingWindowRateLimiter.
๐งฐ Dynamic Registration
All HTTP clients are dynamically registered based on your appsettings.httpHelper.json configuration โ no code changes required to add more.
๐ค Contributing
Pull requests, feedback, and improvements are welcome. This package is part of the CSharpEssentials ecosystem.
๐ฆ Requirements
- .NET 8.0 or higher
- NuGet Packages:
Polly,Microsoft.Extensions.Http,Microsoft.Extensions.Options
๐ License
MIT
| 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 was computed. 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 was computed. 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. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Configuration.Json (>= 9.0.2)
- Microsoft.Extensions.Http (>= 9.0.1)
- Polly (>= 8.5.2)
- System.Threading.RateLimiting (>= 9.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CSharpEssentials.HttpHelper:
| Package | Downloads |
|---|---|
|
CSharpEssentials.HangFireHelper
A library to help you to use HangFire |
|
|
CSharpEssentials.LoggerHelper.AI
C# AI Observability: RAG, Trace Correlation & Anomaly Detection |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.7 | 42 | 11/4/2025 |
| 4.0.6 | 172 | 10/21/2025 |
| 4.0.5 | 178 | 10/20/2025 |
| 4.0.4 | 106 | 10/18/2025 |
| 4.0.3 | 215 | 10/4/2025 |
| 4.0.2 | 300 | 9/12/2025 |
| 4.0.0 | 173 | 9/10/2025 |
| 3.0.1 | 165 | 9/10/2025 |
| 2.0.5 | 182 | 9/7/2025 |
| 2.0.4 | 144 | 9/7/2025 |
| 2.0.3 | 137 | 9/7/2025 |
| 2.0.2 | 214 | 6/14/2025 |
| 2.0.1 | 177 | 6/14/2025 |
| 2.0.0 | 172 | 6/14/2025 |
| 1.2.4 | 285 | 3/3/2025 |
| 1.2.3 | 144 | 3/2/2025 |
| 1.2.2 | 135 | 3/2/2025 |
| 1.2.0 | 139 | 3/2/2025 |
| 1.1.1 | 154 | 2/22/2025 |
| 1.1.0 | 147 | 2/22/2025 |
| 1.0.0 | 519 | 2/2/2025 |