RepletoryLib.Http.Client
1.0.0
dotnet add package RepletoryLib.Http.Client --version 1.0.0
NuGet\Install-Package RepletoryLib.Http.Client -Version 1.0.0
<PackageReference Include="RepletoryLib.Http.Client" Version="1.0.0" />
<PackageVersion Include="RepletoryLib.Http.Client" Version="1.0.0" />
<PackageReference Include="RepletoryLib.Http.Client" />
paket add RepletoryLib.Http.Client --version 1.0.0
#r "nuget: RepletoryLib.Http.Client, 1.0.0"
#:package RepletoryLib.Http.Client@1.0.0
#addin nuget:?package=RepletoryLib.Http.Client&version=1.0.0
#tool nuget:?package=RepletoryLib.Http.Client&version=1.0.0
RepletoryLib.Http.Client
Typed HTTP client with Polly resilience policies (retry, circuit breaker, timeout).
Part of the RepletoryLib ecosystem -- standalone, reusable .NET 10 libraries with zero business logic.
Overview
RepletoryLib.Http.Client provides a typed HTTP client service with built-in Polly resilience policies. Every outgoing request is automatically protected by retry with exponential backoff, a circuit breaker, and a timeout policy. Responses are wrapped in Result<T> for consistent error handling.
Key Features
IHttpClientService-- Typed GET, POST, PUT, PATCH, DELETE returningResult<T>- Retry policy -- Exponential backoff with configurable retry count
- Circuit breaker -- Opens after consecutive failures to prevent cascade
- Timeout -- Per-request timeout protection
- Correlation ID forwarding -- Automatically propagates
X-Correlation-IDto downstream services
Installation
dotnet add package RepletoryLib.Http.Client
Dependencies
| Package | Type |
|---|---|
RepletoryLib.Common |
RepletoryLib |
Microsoft.Extensions.Http.Polly |
NuGet |
Polly |
NuGet (8.5.2) |
Quick Start
using RepletoryLib.Http.Client;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRepletoryHttpClient<IPaymentGateway>(builder.Configuration);
{
"HttpClient": {
"BaseUrl": "https://api.payment-gateway.com",
"TimeoutSeconds": 30,
"RetryCount": 3,
"CircuitBreakerThreshold": 5,
"CircuitBreakerDurationSeconds": 30
}
}
Configuration
HttpClientOptions
| Property | Type | Default | Description |
|---|---|---|---|
BaseUrl |
string |
"" |
Base URL for all requests |
TimeoutSeconds |
int |
30 |
Per-request timeout |
RetryCount |
int |
3 |
Retry attempts with exponential backoff |
CircuitBreakerThreshold |
int |
5 |
Consecutive failures before circuit opens |
CircuitBreakerDurationSeconds |
int |
30 |
Duration circuit stays open |
Usage Examples
Making HTTP Requests
using RepletoryLib.Http.Client.Interfaces;
public class PaymentService
{
private readonly IHttpClientService _http;
public PaymentService(IHttpClientService http) => _http = http;
public async Task<PaymentResult?> ProcessPaymentAsync(PaymentRequest request)
{
var result = await _http.PostAsync<PaymentResult>("/v1/payments", request);
if (result.IsSuccess)
return result.Data;
_logger.LogError("Payment failed: {Error} (Status: {Code})", result.Error, result.StatusCode);
return null;
}
public async Task<Order?> GetOrderAsync(string orderId)
{
var result = await _http.GetAsync<Order>($"/v1/orders/{orderId}");
return result.IsSuccess ? result.Data : null;
}
}
Resilience Behavior
Request 1: POST /v1/payments → 503 (server error)
↳ Retry 1 (after 1s): → 503
↳ Retry 2 (after 2s): → 503
↳ Retry 3 (after 4s): → 200 OK ✓
After 5 consecutive failures:
↳ Circuit breaker OPENS for 30 seconds
↳ All requests fail-fast without calling the server
↳ After 30s, circuit enters half-open state
↳ Next request tests if server has recovered
API Reference
IHttpClientService
| Method | Returns | Description |
|---|---|---|
GetAsync<T>(url) |
Result<T> |
HTTP GET |
PostAsync<T>(url, body) |
Result<T> |
HTTP POST with JSON body |
PutAsync<T>(url, body) |
Result<T> |
HTTP PUT with JSON body |
PatchAsync<T>(url, body) |
Result<T> |
HTTP PATCH with JSON body |
DeleteAsync<T>(url) |
Result<T> |
HTTP DELETE |
All methods return Result<T> -- check IsSuccess before accessing Data.
Integration with Other RepletoryLib Packages
| Package | Relationship |
|---|---|
RepletoryLib.Common |
Result<T> for response wrapping |
RepletoryLib.Api.Middleware |
Correlation ID forwarded to downstream services |
RepletoryLib.Tracing |
HTTP calls instrumented by OpenTelemetry |
Troubleshooting
| Issue | Solution |
|---|---|
| All requests timeout | Check BaseUrl and TimeoutSeconds. Ensure the target service is reachable. |
| Circuit breaker stuck open | Wait for CircuitBreakerDurationSeconds to elapse, or restart the application. |
| Retries not working | Only 5xx and network errors trigger retries. 4xx errors are not retried. |
License
This project is licensed under the MIT License.
Copyright (c) 2024-2026 Repletory.
For complete documentation, infrastructure setup, and configuration reference, see the RepletoryLib main repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Http.Polly (>= 10.0.0)
- Polly (>= 8.5.2)
- RepletoryLib.Common (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 79 | 3/2/2026 |