Franz.Common.Http.Refit
1.6.2
See the version list below for details.
dotnet add package Franz.Common.Http.Refit --version 1.6.2
NuGet\Install-Package Franz.Common.Http.Refit -Version 1.6.2
<PackageReference Include="Franz.Common.Http.Refit" Version="1.6.2" />
<PackageVersion Include="Franz.Common.Http.Refit" Version="1.6.2" />
<PackageReference Include="Franz.Common.Http.Refit" />
paket add Franz.Common.Http.Refit --version 1.6.2
#r "nuget: Franz.Common.Http.Refit, 1.6.2"
#:package Franz.Common.Http.Refit@1.6.2
#addin nuget:?package=Franz.Common.Http.Refit&version=1.6.2
#tool nuget:?package=Franz.Common.Http.Refit&version=1.6.2
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.2
Goals
- Make outbound HTTP clients trivial and consistent across services.
- Reuse Franz primitives (eg.
MediatorContextfor 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 optionalX-User-Idheaders viaFranzRefitHeadersHandler. - Optional
FranzRefitAuthHandlerdriven by a pluggableITokenProviderfor Bearer tokens. - Optional Polly policy attachment using the host
IPolicyRegistry<string>(viaAddPolicyHandlerFromRegistry). - Activity enrichment: annotates
Activity.Currentwithfranz.http.*tags (host controls exporters). - Lightweight metrics via
System.Diagnostics.Metrics(meter nameFranz.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 : DelegatingHandlerInjects correlation/tenant/user headers, logs a basic request/response entry, annotatesActivity.Current, and records metrics.FranzRefitAuthHandler : DelegatingHandlerPluggable token injection. UsesITokenProviderif registered; otherwise a no-op provider is used.RefitClientOptionsPer-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.Policyis optional � if provided, Franz will attach the named policy from the host's policy registry.
Dependencies & recommended versions (NET 9.0.8 compatible)
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.HttpClientFactoryprovidesAddRefitClient<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-IDandX-Tenant-Id. - Auth handler uses
ITokenProviderwhen present. - Refit client registration attaches Polly policies when the registry contains them (integration test with
TestServer/IHttpClientFactory).
- Header handler adds
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. Addusing Refit;at the top of registration code.
- Ensure
Refit clients not registered via bootstrapper
- Ensure
Franz:HttpClients:EnableRefitistrueand host project referencesFranz.Common.Http.Refit. ProvideInterfaceTypein config if automatic discovery fails.
- Ensure
Polly policy not applied
- Register your policies in the
IPolicyRegistry<string>prior to callingAddFranzRefit(example:services.AddPolicyRegistry().Add("DefaultHttpRetry", policy)).
- Register your policies in the
Token injection missing
- Register an
ITokenProviderthat returns tokens viaGetTokenAsync. If none is registered, the auth handler no-ops.
- Register an
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>.
- New:
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 | Versions 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. |
-
net9.0
- Franz.Common.Mediator (>= 1.6.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Http (>= 9.0.9)
- Microsoft.Extensions.Http.Polly (>= 9.0.9)
- OpenTelemetry.Api (>= 1.12.0)
- Polly (>= 8.6.3)
- Refit (>= 8.0.0)
- Refit.HttpClientFactory (>= 8.0.0)
- Serilog (>= 4.3.0)
- Serilog.AspNetCore (>= 9.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 |
|---|---|---|
| 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 |