WebSpark.HttpClientUtility

Core HTTP utilities for .NET 8-10 applications: authentication providers (Bearer, Basic, API Key), response caching, Polly resilience (retry/circuit breaker), OpenTelemetry integration, concurrent requests, fire-and-forget operations, and streaming support. Lightweight package focused on HTTP client functionality. Supports .NET 8 LTS, .NET 9, and .NET 10 (Preview). For web crawling features, see WebSpark.HttpClientUtility.Crawler package.

v2.1.1 2.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.