WebSpark.HttpClientUtility
A Production-Ready NuGet Package for Resilient HTTP Clients in .NET
dotnet add package WebSpark.HttpClientUtility
Resilience Patterns
Built-in support for retry logic, circuit breakers, and fallback strategies using Polly. Handle transient faults gracefully and keep your applications running smoothly.
Performance Optimized
Leverage HttpClientFactory for efficient connection pooling and resource management. Includes advanced features like request/response logging with minimal performance impact.
Easy Integration
Simple dependency injection setup with extensive configuration options. Works seamlessly with ASP.NET Core and follows modern .NET best practices.
Key Features
Resilience Policies
- Automatic retry with exponential backoff
- Circuit breaker pattern implementation
- Fallback strategies for graceful degradation
- Timeout policies for request management
Advanced Features
- Comprehensive request/response logging
- Performance telemetry and metrics
- HttpClientFactory integration
- Dependency injection ready
Quick Start Example
Getting started with WebSpark.HttpClientUtility is simple. Install the package and configure your HTTP clients with built-in resilience patterns.
Step 1: Install the Package
dotnet add package WebSpark.HttpClientUtility
Step 2: Configure Services
// Add to your Program.cs or Startup.cs
builder.Services.AddHttpClient("ResilientClient")
.AddPolicyHandler(GetRetryPolicy())
.AddPolicyHandler(GetCircuitBreakerPolicy());
static IAsyncPolicy GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.WaitAndRetryAsync(3, retryAttempt =>
TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
static IAsyncPolicy GetCircuitBreakerPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
}
Step 3: Use in Your Application
public class MyService
{
private readonly IHttpClientFactory _httpClientFactory;
public MyService(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public async Task GetDataAsync()
{
var client = _httpClientFactory.CreateClient("ResilientClient");
var response = await client.GetAsync("https://api.example.com/data");
return await response.Content.ReadAsStringAsync();
}
}
Live Demonstrations
Explore the demos below to see WebSpark.HttpClientUtility in action. Each example showcases different features and resilience patterns implemented in the package.
Polly Integration
See retry policies and circuit breakers in action with real-world scenarios.
View DemoReady to Build Resilient Applications?
WebSpark.HttpClientUtility provides everything you need to create production-ready HTTP clients with minimal configuration. Built for .NET 10, it follows modern best practices and includes comprehensive documentation.