WebSpark.HttpClientUtility
1.5.1
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
<PackageReference Include="WebSpark.HttpClientUtility" Version="1.5.1" />
<PackageVersion Include="WebSpark.HttpClientUtility" Version="1.5.1" />
<PackageReference Include="WebSpark.HttpClientUtility" />
paket add WebSpark.HttpClientUtility --version 1.5.1
#r "nuget: WebSpark.HttpClientUtility, 1.5.1"
#:package WebSpark.HttpClientUtility@1.5.1
#addin nuget:?package=WebSpark.HttpClientUtility&version=1.5.1
#tool nuget:?package=WebSpark.HttpClientUtility&version=1.5.1
WebSpark.HttpClientUtility
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
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
- Getting Started Guide - Complete walkthrough
- Configuration Options - All settings explained
- Caching Guide - Response caching strategies
- Resilience Guide - Retry and circuit breaker patterns
- Web Crawling - Site crawler features
- Migration Guide - From raw HttpClient
- API Reference - Complete API 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.
- Fork the repository
- Create a feature branch
- Add tests for your changes
- Ensure all tests pass
- 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
📦 Related Packages
- WebSpark.HttpClientUtility.Testing - Test helpers (coming soon)
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
Questions or Issues? Open an issue or start a discussion!
| 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 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. |
-
net8.0
- CsvHelper (>= 33.1.0)
- HtmlAgilityPack (>= 1.12.4)
- Markdig (>= 0.43.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry (>= 1.13.1)
- OpenTelemetry.Exporter.Console (>= 1.13.1)
- OpenTelemetry.Exporter.InMemory (>= 1.13.1)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.13.1)
- OpenTelemetry.Extensions.Hosting (>= 1.13.1)
- OpenTelemetry.Instrumentation.Http (>= 1.13.0)
- Polly (>= 8.6.4)
-
net9.0
- CsvHelper (>= 33.1.0)
- HtmlAgilityPack (>= 1.12.4)
- Markdig (>= 0.43.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry (>= 1.13.1)
- OpenTelemetry.Exporter.Console (>= 1.13.1)
- OpenTelemetry.Exporter.InMemory (>= 1.13.1)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.13.1)
- OpenTelemetry.Extensions.Hosting (>= 1.13.1)
- OpenTelemetry.Instrumentation.Http (>= 1.13.0)
- Polly (>= 8.6.4)
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.