HttpEase 1.2.0
dotnet add package HttpEase --version 1.2.0
NuGet\Install-Package HttpEase -Version 1.2.0
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="HttpEase" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpEase" Version="1.2.0" />
<PackageReference Include="HttpEase" />
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 HttpEase --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HttpEase, 1.2.0"
#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 HttpEase@1.2.0
#: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=HttpEase&version=1.2.0
#tool nuget:?package=HttpEase&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HttpEase
Simple, powerful HTTP client for .NET with retry, logging, result wrapper, typed clients, and enterprise-level Polly integration.
Install
dotnet add package HttpEase
Quick Start
Basic Usage
services.AddHttpEase("https://api.example.com");
var client = provider.GetRequiredService<HttpEaseClient>();
var user = await client.GetAsync<User>("/users/1");
Safe Calls with Result Wrapper
var result = await client.TryGetAsync<User>("/users/1");
if(result.Success)
{
Console.WriteLine(result.Data);
}
else
{
Console.WriteLine($"Error: {result.Error}");
}
Typed Client Support (Major Feature)
Create strongly-typed API clients by inheriting from HttpEaseClient:
Step 1: Create Your Typed Client
public class UserApiClient : HttpEaseClient
{
public UserApiClient(HttpClient http, ILogger<UserApiClient> logger)
: base(http, logger)
{
}
public async Task<User?> GetUserAsync(int userId)
{
return await GetAsync<User>($"/users/{userId}");
}
public async Task<User?> CreateUserAsync(CreateUserRequest request)
{
return await PostAsync<CreateUserRequest, User>("/users", request);
}
}
Step 2: Register in Dependency Injection
// Option 1: Basic typed client
services.AddHttpEaseTypedClient<UserApiClient>("https://api.example.com");
// Option 2: Typed client with Polly policies
var policy = HttpEase.Policies.PollyPolicyFactory.CreateCombinedPolicy();
services.AddHttpEaseTypedClientWithPolly<UserApiClient>(
"https://api.example.com",
policy);
Step 3: Use in Your Application
var userClient = provider.GetRequiredService<UserApiClient>();
var user = await userClient.GetUserAsync(1);
var newUser = await userClient.CreateUserAsync(new CreateUserRequest
{
Name = "John",
Email = "john@example.com"
});
Polly Integration (Enterprise Level)
Advanced resilience and fault-handling with Polly policies:
Step 1: Configure Policies
// Retry policy
var retryPolicy = HttpEase.Policies.PollyPolicyFactory.CreateRetryPolicy(
retryCount: 3,
delayBetweenRetries: TimeSpan.FromSeconds(1));
// Circuit breaker policy
var circuitBreakerPolicy = HttpEase.Policies.PollyPolicyFactory.CreateCircuitBreakerPolicy(
failureThreshold: 5,
timeout: TimeSpan.FromSeconds(30));
// Timeout policy
var timeoutPolicy = HttpEase.Policies.PollyPolicyFactory.CreateTimeoutPolicy(
timeoutDuration: TimeSpan.FromSeconds(30));
// Combined policy (recommended)
var combinedPolicy = HttpEase.Policies.PollyPolicyFactory.CreateCombinedPolicy(
retryCount: 3,
failureThreshold: 5,
timeoutDuration: TimeSpan.FromSeconds(30),
circuitBreakerTimeout: TimeSpan.FromSeconds(30),
retryDelay: TimeSpan.FromSeconds(1));
// Bulkhead isolation policy
var bulkheadPolicy = HttpEase.Policies.PollyPolicyFactory.CreateBulkheadPolicy(
maxParallelization: 10,
maxQueuingActions: 5);
Step 2: Apply Policies
// Basic HttpEaseClient with Polly
services.AddHttpEaseWithPolly(
"https://api.example.com",
combinedPolicy);
// Typed client with Polly
services.AddHttpEaseTypedClientWithPolly<UserApiClient>(
"https://api.example.com",
combinedPolicy);
// Without custom policy (uses smart defaults)
services.AddHttpEaseWithPolly("https://api.example.com");
Available Policies
| Policy | Purpose |
|---|---|
| RetryPolicy | Retry failed requests with exponential backoff |
| CircuitBreakerPolicy | Fail fast when service is down |
| TimeoutPolicy | Cancel requests exceeding timeout |
| BulkheadPolicy | Limit concurrent requests |
| CombinedPolicy | Wraps retry, circuit breaker, and timeout (recommended) |
Real-World Example
// Startup
var productApiPolicy = HttpEase.Policies.PollyPolicyFactory.CreateCombinedPolicy(
retryCount: 3,
failureThreshold: 5,
timeoutDuration: TimeSpan.FromSeconds(10));
services.AddHttpEaseTypedClientWithPolly<ProductApiClient>(
"https://api.products.com",
productApiPolicy);
// Usage
public class ProductService
{
private readonly ProductApiClient _client;
public ProductService(ProductApiClient client)
{
_client = client;
}
public async Task<Product?> FetchProductAsync(int id)
{
// Automatically handled by Polly policies:
// - retries on transient failures
// - fails fast after circuit opens
// - enforces 10-second timeout
return await _client.GetProductAsync(id);
}
}
Core Features
- ✅ Typed Clients - Create strongly-typed API clients
- ✅ Polly Integration - Enterprise resilience policies
- ✅ Retry Support - Configurable retry logic
- ✅ Logging - Built-in logging for all requests
- ✅ Result Wrapper - Safe error handling with Result<T>
- ✅ JSON Serialization - Automatic JSON handling
- ✅ Clean DI - First-class dependency injection support
Examples
See the Examples/ folder for complete implementations:
UserApiClient.cs- Simple typed client patternProductApiClient.cs- Error handling with Result<T>
License
MIT
| 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 was computed. 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.
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Console (>= 8.0.0)
- Polly (>= 8.2.0)
- Polly.Contrib.WaitAndRetry (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.