WebSpark.HttpClientUtility

Drop-in HttpClient wrapper for .NET 8-10+ with Polly resilience, response caching, and OpenTelemetry. One-line setup eliminates boilerplate for retries, circuit breakers, correlation IDs, and structured logging. Perfect for microservices, APIs, and web scrapers. Includes authentication providers (Bearer, Basic, API Key), concurrent requests, fire-and-forget operations, and streaming support. MIT licensed, 252+ tests. For web crawling features, see WebSpark.HttpClientUtility.Crawler package.

v2.1.2 3.4K downloads
dotnet add package WebSpark.HttpClientUtility

Why Choose This Library?

Features

Simple one-line service registration
No complex configuration required. Just call services.AddHttpClientUtility() and you're ready to go.

Built-in resilience with Polly integration
Automatic retry policies, circuit breakers, and timeout handling out of the box.

Automatic response caching
Intelligent caching with configurable duration and cache invalidation strategies.

Comprehensive telemetry and logging
OpenTelemetry integration with correlation IDs for distributed tracing.

Web crawling capabilities
Robots.txt parsing, SignalR progress updates, and concurrent crawling support.

Flexible authentication
Built-in providers for Bearer tokens, Basic auth, and API keys.

Quick Example

// Register services with optional features
builder.Services.AddHttpClientUtility(options => {
    options.EnableCaching = true;
    options.EnableResilience = true;
    options.EnableTelemetry = true;
});

// Make HTTP requests with automatic retries and caching
var request = new HttpRequestResult<WeatherData>
{
    RequestPath = "https://api.example.com/weather",
    RequestMethod = HttpMethod.Get,
    CacheDurationMinutes = 10, // Optional caching
    AuthenticationProvider = new BearerTokenAuthenticationProvider("your-token")
};

var result = await _httpService.HttpSendRequestResultAsync(request);

if (result.IsSuccessStatusCode)
{
    var weather = result.ResponseResults;
    Console.WriteLine($"Temperature: {weather.Temperature}°C");
}

Get Started

What's Included

The library provides a complete HTTP client wrapper with:

Architecture

The library uses a decorator pattern for composing features:

  1. Base Service: Core HTTP request functionality
  2. Cache Decorator: Adds caching capabilities (optional)
  3. Resilience Decorator: Adds Polly policies (optional)
  4. Telemetry Decorator: Adds metrics and tracing (optional)

This design allows you to enable only the features you need while maintaining clean, testable code.

Targets

License

Licensed under MIT. Free for commercial and open-source use.