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
                    
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="RepletoryLib.Http.Client" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RepletoryLib.Http.Client" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RepletoryLib.Http.Client" />
                    
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 RepletoryLib.Http.Client --version 1.0.0
                    
#r "nuget: RepletoryLib.Http.Client, 1.0.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 RepletoryLib.Http.Client@1.0.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=RepletoryLib.Http.Client&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RepletoryLib.Http.Client&version=1.0.0
                    
Install as a Cake Tool

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.

NuGet .NET 10 License: MIT


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

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