Franz.Common.Http.Refit 1.6.15

There is a newer version of this package available.
See the version list below for details.
dotnet add package Franz.Common.Http.Refit --version 1.6.15
                    
NuGet\Install-Package Franz.Common.Http.Refit -Version 1.6.15
                    
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="Franz.Common.Http.Refit" Version="1.6.15" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Franz.Common.Http.Refit" Version="1.6.15" />
                    
Directory.Packages.props
<PackageReference Include="Franz.Common.Http.Refit" />
                    
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 Franz.Common.Http.Refit --version 1.6.15
                    
#r "nuget: Franz.Common.Http.Refit, 1.6.15"
                    
#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 Franz.Common.Http.Refit@1.6.15
                    
#: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=Franz.Common.Http.Refit&version=1.6.15
                    
Install as a Cake Addin
#tool nuget:?package=Franz.Common.Http.Refit&version=1.6.15
                    
Install as a Cake Tool

Franz.Common.Http.Refit

Package: Franz.Common.Http.Refit

Refit integration for the Franz Framework � production-oriented, small-surface, high-value. Provides typed Refit clients pre-wired with: correlation & tenant header propagation, optional token injection, Polly policy integration, Serilog-friendly logging, and OpenTelemetry-friendly annotations & lightweight metrics.


  • Current Version: 1.6.15

Goals

  • Make outbound HTTP clients trivial and consistent across services.
  • Reuse Franz primitives (eg. MediatorContext for correlation/tenant data and your shared Polly registry).
  • Keep the API small and predictable while shipping production ergonomics by default.

Features

  • AddFranzRefit<TClient>(...) � single-line registration for typed Refit clients.
  • Automatic injection of X-Correlation-ID, X-Tenant-Id, and optional X-User-Id headers via FranzRefitHeadersHandler.
  • Optional FranzRefitAuthHandler driven by a pluggable ITokenProvider for Bearer tokens.
  • Optional Polly policy attachment using the host IPolicyRegistry<string> (via AddPolicyHandlerFromRegistry).
  • Activity enrichment: annotates Activity.Current with franz.http.* tags (host controls exporters).
  • Lightweight metrics via System.Diagnostics.Metrics (meter name Franz.Refit): request count, failures, duration histogram.
  • Small test surface (header handler unit-tested pattern included).

Quickstart

Add package

dotnet add package Franz.Common.Http.Refit --version 1.4.1
# Ensure host references Refit.HttpClientFactory and Polly packages (see Dependencies)

Example typed client

using Refit;
public interface IWeatherApi
{
  [Get("/weather/today/{city}")]
  Task<WeatherDto> GetTodayAsync(string city);
}

public record WeatherDto(string City, int TemperatureCelsius, string Summary);

Manual registration (code)

// register a shared policy registry first (if you want policies)
builder.Services.AddPolicyRegistry()
  .Add("DefaultHttpRetry", HttpPolicyExtensions
    .HandleTransientHttpError()
    .WaitAndRetryAsync(new[] { TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(300) }));

// register Refit client wired by Franz
builder.Services.AddFranzRefit<MyApp.ApiClients.IWeatherApi>(
    name: "Weather",
    baseUrl: "https://api.weather.local",
    policyName: "DefaultHttpRetry");

Configuration-driven registration (via Franz.Common.Http.Bootstrap)

If Franz.Common.Http.Bootstrap is used and Franz:HttpClients:EnableRefit = true, the bootstrapper will register clients defined under Franz:HttpClients:Apis automatically (see bootstrap README for schema).


API surface (key types)

  • AddFranzRefit<TClient>(IServiceCollection services, string name, string baseUrl, string? policyName = null, Action<RefitSettings>? configureRefitSettings = null, Action<RefitClientOptions>? configureOptions = null) Registers a typed Refit client with header and auth handlers and optional policy.

  • FranzRefitHeadersHandler : DelegatingHandler Injects correlation/tenant/user headers, logs a basic request/response entry, annotates Activity.Current, and records metrics.

  • FranzRefitAuthHandler : DelegatingHandler Pluggable token injection. Uses ITokenProvider if registered; otherwise a no-op provider is used.

  • RefitClientOptions Per-package options: default timeout, enable OTEL tagging, default policy name, etc.


appsettings example (for bootstrapper usage)

{
  "Franz": {
    "HttpClients": {
      "EnableRefit": true,
      "Apis": {
        "Weather": {
          "InterfaceType": "MyApp.ApiClients.IWeatherApi, MyApp",
          "BaseUrl": "https://api.weather.local",
          "Policy": "DefaultHttpRetry"
        }
      }
    }
  }
}
  • InterfaceType (assembly-qualified) is recommended for deterministic resolution.
  • Policy is optional � if provided, Franz will attach the named policy from the host's policy registry.

The host project should reference (or the package may include where appropriate):

<PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" />
<PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.9" />
<PackageReference Include="Polly" Version="8.6.3" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.9" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0" />

Lock versions per your mono-repo policy. Refit.HttpClientFactory provides AddRefitClient<T>() � ensure it is referenced in the project that calls the registration.


Testing

  • Unit test skeleton included for FranzRefitHeadersHandler (validates header injection).

  • Suggested tests:

    • Header handler adds X-Correlation-ID and X-Tenant-Id.
    • Auth handler uses ITokenProvider when present.
    • Refit client registration attaches Polly policies when the registry contains them (integration test with TestServer/IHttpClientFactory).

Example unit test pattern:

[Fact]
public async Task SendAsync_AddsCorrelationAndTenantHeaders()
{
  MediatorContext.Reset();
  MediatorContext.Current.TenantId = "tenant-42";
  MediatorContext.Current.CorrelationId = "corr-123";

  var inner = new TestHttpMessageHandler((req, ct) => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)));
  var handler = new FranzRefitHeadersHandler(new NullLogger<FranzRefitHeadersHandler>()) { InnerHandler = inner };

  var invoker = new HttpMessageInvoker(handler);
  var response = await invoker.SendAsync(new HttpRequestMessage(HttpMethod.Get, "https://dummy/test"), CancellationToken.None);

  Assert.True(inner.LastRequest.Headers.Contains("X-Correlation-ID"));
  Assert.True(inner.LastRequest.Headers.Contains("X-Tenant-Id"));
}

Troubleshooting

  • AddRefitClient<T>() not found

    • Ensure Refit.HttpClientFactory (or an equivalent Refit package that exposes factory helpers) is referenced in the same project that performs the registration. Add using Refit; at the top of registration code.
  • Refit clients not registered via bootstrapper

    • Ensure Franz:HttpClients:EnableRefit is true and host project references Franz.Common.Http.Refit. Provide InterfaceType in config if automatic discovery fails.
  • Polly policy not applied

    • Register your policies in the IPolicyRegistry<string> prior to calling AddFranzRefit (example: services.AddPolicyRegistry().Add("DefaultHttpRetry", policy)).
  • Token injection missing

    • Register an ITokenProvider that returns tokens via GetTokenAsync. If none is registered, the auth handler no-ops.

Changelog (recent)

  • v1.4.1

    • New: AddFranzRefit<TClient>() extension for typed Refit clients.
    • New: FranzRefitHeadersHandler � correlation/tenant headers, logging, OTEL tags, metrics.
    • New: Optional ITokenProvider + FranzRefitAuthHandler.
    • New: Polly policy reuse via host IPolicyRegistry<string>.

Publishing & Release Checklist

  • Bump package version to 1.4.1.
  • Build & run unit tests.
  • dotnet pack -c Release ? produce .nupkg.
  • dotnet nuget push ./bin/Release/*.nupkg -k $NUGET_API_KEY -s <feed> (or use your private feed).
  • Update top-level Franz changelog & bootstrap README to mention Refit integration.

Contributing & License

Part of the private Franz Framework. Follow internal contribution guidelines. Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
2.0.2 82 3/30/2026
2.0.1 86 3/29/2026
1.7.8 90 3/2/2026
1.7.7 106 1/31/2026
1.7.6 110 1/22/2026
1.7.5 104 1/10/2026
1.7.4 103 12/27/2025
1.7.3 185 12/22/2025
1.7.2 180 12/21/2025
1.7.1 132 12/20/2025
1.7.0 279 12/16/2025
1.6.21 198 11/27/2025
1.6.20 210 11/24/2025
1.6.19 153 10/25/2025
1.6.15 182 10/20/2025
1.6.14 191 10/15/2025
1.6.3 203 10/9/2025
1.6.2 185 10/7/2025
1.5.9 192 9/24/2025
1.5.4 199 9/23/2025
Loading failed