GM.HttpClient 1.2.0

dotnet add package GM.HttpClient --version 1.2.0
                    
NuGet\Install-Package GM.HttpClient -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="GM.HttpClient" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GM.HttpClient" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="GM.HttpClient" />
                    
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 GM.HttpClient --version 1.2.0
                    
#r "nuget: GM.HttpClient, 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 GM.HttpClient@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=GM.HttpClient&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=GM.HttpClient&version=1.2.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.HttpClient/master/icon.png" alt="GM.HttpClient" width="140" height="140" /> </p>

GM.HttpClient

CI NuGet License: MIT

A lightweight, dependency-injection-friendly HttpClient for .NET. One registration call wires a Refit client to a typed options section and layers on a configurable Polly resilience pipeline plus a set of delegating handlers. Part of the GM.* family of packages. Targets net10.0.

Out of the box each client gets:

  • Resilience — retry (exponential backoff), circuit breaker, timeout, and an optional fallback response.
  • Authorization — optional Basic auth from configuration.
  • Response caching — in-memory caching of successful GET responses.
  • Header injection — static headers applied to every request.
  • Context propagation — forwards the caller's IP as X-Client-IP when an HttpContext is present.
  • Structured logging — request/response logging with timing via ILogger.

Install

dotnet add package GM.HttpClient

Uses the ASP.NET Core shared framework (Microsoft.AspNetCore.App) for IHttpContextAccessor, so consumers should build on the ASP.NET Core (Microsoft.NET.Sdk.Web) SDK.

Configure

Bind options from a configuration section (shape matches GMAPIClientOptions):

{
  "GitHubApi": {
    "BaseUrl": "https://api.github.com",
    "Headers": { "User-Agent": "my-app" },
    "RetryPolicy": { "RetryCount": 3 },
    "CircuitBreakerPolicy": { "FailureThreshold": 2, "BreakDuration": "00:00:30" },
    "TimeoutPolicy": { "Timeout": "00:00:10" },
    "FallbackPolicy": { "UseFallback": true },
    "Authorization": { "UseAuthorization": false },
    "Caching": { "EnableCaching": true, "CacheDuration": "00:05:00" }
  }
}

Register

Define a Refit interface, then register it against a configuration section and a client name:

using GM.HttpClient;
using Refit;

public interface IGitHubApi
{
    [Get("/users/{user}")]
    Task<GitHubUser> GetUserAsync(string user);
}

var section = builder.Configuration.GetSection("GitHubApi");

builder.Services.AddGMHttpClient<IGitHubApi, GMAPIClientOptions>(
    configSection: section,
    clientName: "GitHubApi");

Use

Inject the Refit interface anywhere — the resilience pipeline and handlers run on every call:

public class ProfileService(IGitHubApi api)
{
    public Task<GitHubUser> GetAsync(string user) => api.GetUserAsync(user);
}

AddGMHttpClient also accepts optional hooks for extra registrations and custom handlers:

builder.Services.AddGMHttpClient<IGitHubApi, GMAPIClientOptions>(
    section,
    "GitHubApi",
    additionalConfig: (services, cfg) => { /* extra options binding */ },
    customHandlers:   services => { /* register your own DelegatingHandlers */ });

Contributing & releases

Versioning, tags, the changelog, and publishing are automated from Conventional Commits — see CONTRIBUTING.md.

License

MIT — see LICENSE.

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.2.0 100 7/30/2026
1.1.0 112 7/2/2026
1.0.0 242 5/1/2025