WebSpark.HttpClientUtility 1.5.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package WebSpark.HttpClientUtility --version 1.5.1
                    
NuGet\Install-Package WebSpark.HttpClientUtility -Version 1.5.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebSpark.HttpClientUtility" Version="1.5.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WebSpark.HttpClientUtility" Version="1.5.1" />
                    
Directory.Packages.props
<PackageReference Include="WebSpark.HttpClientUtility" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WebSpark.HttpClientUtility --version 1.5.1
                    
#r "nuget: WebSpark.HttpClientUtility, 1.5.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WebSpark.HttpClientUtility@1.5.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WebSpark.HttpClientUtility&version=1.5.1
                    
Install as a Cake Addin
#tool nuget:?package=WebSpark.HttpClientUtility&version=1.5.1
                    
Install as a Cake Tool

WebSpark.HttpClientUtility

NuGet Version NuGet Downloads License: MIT Build Status .NET 8+ Documentation

A production-ready HttpClient wrapper for .NET 8+ that makes HTTP calls simple, resilient, and observable.

Stop writing boilerplate HTTP code. Get built-in resilience, caching, telemetry, and structured logging out of the box.

📚 Documentation

View Full Documentation →

The complete documentation site includes:

  • Getting started guide
  • Feature documentation
  • API reference
  • Code examples
  • Best practices

⚡ Quick Start

Install

dotnet add package WebSpark.HttpClientUtility

5-Minute Example

// Program.cs - Register services (ONE LINE!)
builder.Services.AddHttpClientUtility();

// YourService.cs - Make requests
public class WeatherService
{
    private readonly IHttpRequestResultService _httpService;
    
    public WeatherService(IHttpRequestResultService httpService) => _httpService = httpService;

    public async Task<WeatherData?> GetWeatherAsync(string city)
    {
        var request = new HttpRequestResult<WeatherData>
        {
     RequestPath = $"https://api.weather.com/forecast?city={city}",
     RequestMethod = HttpMethod.Get
        };
 
        var result = await _httpService.HttpSendRequestResultAsync(request);
        return result.IsSuccessStatusCode ? result.ResponseResults : null;
    }
}

That's it! You now have:

  • ✅ Automatic correlation IDs for tracing
  • ✅ Structured logging with request/response details
  • ✅ Request timing telemetry
  • ✅ Proper error handling and exception management
  • ✅ Support for .NET 8 LTS and .NET 9

🎯 Why Choose This Library?

Challenge Solution
Boilerplate Code One-line service registration replaces 50+ lines of manual setup
Transient Failures Built-in Polly integration for retries and circuit breakers
Repeated API Calls Automatic response caching with customizable duration
Observability Correlation IDs, structured logging, and OpenTelemetry support
Testing All services are interface-based for easy mocking

🚀 Features

Core Features (Always Included)

  • Simple API - Intuitive request/response model
  • Correlation IDs - Automatic tracking across distributed systems
  • Structured Logging - Rich context in all log messages
  • Telemetry - Request timing and performance metrics
  • Error Handling - Standardized exception processing
  • Type-Safe - Strongly-typed request and response models

Optional Features (Enable as Needed)

  • Caching - In-memory response caching
  • Resilience - Polly retry and circuit breaker policies
  • Concurrent Requests - Parallel request processing
  • Web Crawling - Site crawling with robots.txt support
  • OpenTelemetry - Full observability integration

📚 Common Scenarios

Enable Caching

builder.Services.AddHttpClientUtility(options =>
{
    options.EnableCaching = true;
});

// In your service
var request = new HttpRequestResult<Product>
{
    RequestPath = "https://api.example.com/products/123",
    RequestMethod = HttpMethod.Get,
    CacheDurationMinutes = 10  // Cache for 10 minutes
};

Add Resilience (Retry + Circuit Breaker)

builder.Services.AddHttpClientUtility(options =>
{
    options.EnableResilience = true;
  options.ResilienceOptions.MaxRetryAttempts = 3;
    options.ResilienceOptions.RetryDelay = TimeSpan.FromSeconds(2);
});

All Features Enabled

builder.Services.AddHttpClientUtilityWithAllFeatures();

📖 Documentation

🎓 Sample Projects

Explore working examples in the samples directory:

  • BasicUsage - Simple GET/POST requests
  • WithCaching - Response caching implementation
  • WithResilience - Retry and circuit breaker patterns
  • ConcurrentRequests - Parallel request processing
  • WebCrawler - Site crawling example

🆚 Comparison to Alternatives

Feature WebSpark.HttpClientUtility Raw HttpClient RestSharp Refit
Setup Complexity ⭐ One line ⭐⭐⭐ Manual ⭐⭐ Low ⭐⭐ Low
Built-in Caching ✅ Yes ❌ Manual ❌ Manual ⚠️ Plugin
Built-in Resilience ✅ Yes ❌ Manual ❌ Manual ❌ Manual
Telemetry ✅ Built-in ⚠️ Manual ⚠️ Manual ⚠️ Manual
Type Safety ✅ Yes ⚠️ Partial ✅ Yes ✅ Yes
Web Crawling ✅ Yes ❌ No ❌ No ❌ No
.NET 8 LTS Support ✅ Yes ✅ Yes ✅ Yes ✅ Yes

🤝 Contributing

Contributions are welcome! See our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for your changes
  4. Ensure all tests pass
  5. Submit a pull request

📊 Project Stats

  • 252+ Unit Tests - 100% passing
  • Supports .NET 8 LTS & .NET 9
  • MIT Licensed - Free for commercial use
  • Active Maintenance - Regular updates

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Questions or Issues? Open an issue or start a discussion!

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on WebSpark.HttpClientUtility:

Package Downloads
WebSpark.Bootswatch

WebSpark.Bootswatch provides Bootswatch themes for ASP.NET Core applications. It includes custom themes and styles that can be easily integrated with ASP.NET Core MVC or Razor Pages applications. Supports .NET 8.0, 9.0, and 10.0.

WebSpark.HttpClientUtility.Crawler

Web crawling capabilities for WebSpark.HttpClientUtility: SiteCrawler and SimpleSiteCrawler with robots.txt compliance, HTML link extraction (HtmlAgilityPack), sitemap generation (Markdig), CSV export (CsvHelper), and real-time SignalR progress updates. Supports .NET 8 LTS, .NET 9, and .NET 10 (Preview). Requires WebSpark.HttpClientUtility base package [2.1.0]. Install both packages and call AddHttpClientUtility() + AddHttpClientCrawler() in your DI registration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 120 11/12/2025
2.0.0 185 11/5/2025
1.5.1 172 11/2/2025
1.5.0 174 11/2/2025
1.4.0 187 11/2/2025
1.3.2 126 11/1/2025
1.3.0 168 10/7/2025
1.2.0 127 9/26/2025
1.1.0 223 7/1/2025
1.0.10 122 5/24/2025
1.0.8 215 5/19/2025
1.0.5 309 5/4/2025
1.0.4 166 5/3/2025
1.0.3 110 5/3/2025
1.0.2 105 5/3/2025
0.1.0 74 5/3/2025

1.5.1 - Quality improvements: Enabled TreatWarningsAsErrors solution-wide with zero-warning baseline. All 520 tests passing across .NET 8 and .NET 9. Fixed npm security vulnerabilities in documentation dependencies.
1.5.0 - Documentation release: Launched comprehensive documentation website at https://markhazleton.github.io/WebSpark.HttpClientUtility/ with getting started guides, API reference, feature documentation, and live NuGet stats. Eleventy-based static site with 95+ Lighthouse scores and automated GitHub Actions deployment.
1.4.0 - Major update: Added .NET 8 LTS support alongside .NET 9 for broader compatibility. Simplified DI registration with extension methods. Improved documentation structure.
1.3.2 - Bug fixes: Fixed CurlCommandSaver tests for proper configuration handling. Improved test reliability and mock setup patterns.
1.3.1 - Enhanced CurlCommandSaver with batch processing, file rotation, sensitive data sanitization, and improved error handling with retry logic. Added comprehensive configuration options and better resource management.
1.3.0 - Major update: Target only .NET 9 production for improved performance and modern features. Removed .NET 8 support to focus on latest stable .NET version. Updated test coverage with 75+ new tests across authentication providers, object pooling, streaming, and utility classes.