Franz.Common.Http.Refit
1.7.1
See the version list below for details.
dotnet add package Franz.Common.Http.Refit --version 1.7.1
NuGet\Install-Package Franz.Common.Http.Refit -Version 1.7.1
<PackageReference Include="Franz.Common.Http.Refit" Version="1.7.1" />
<PackageVersion Include="Franz.Common.Http.Refit" Version="1.7.1" />
<PackageReference Include="Franz.Common.Http.Refit" />
paket add Franz.Common.Http.Refit --version 1.7.1
#r "nuget: Franz.Common.Http.Refit, 1.7.1"
#:package Franz.Common.Http.Refit@1.7.1
#addin nuget:?package=Franz.Common.Http.Refit&version=1.7.1
#tool nuget:?package=Franz.Common.Http.Refit&version=1.7.1
Franz.Common.Http.Refit
Package: Franz.Common.Http.Refit
Refit integration for the Franz Framework — production-oriented, small-surface, and highly modular. Provides typed Refit clients pre-wired with correlation and tenant propagation, optional authentication, resilience with Polly, Serilog-friendly logging, and OpenTelemetry-friendly instrumentation.
- Current Version: 1.7.01
- Part of the private Franz Framework ecosystem.
Goals
- Simplify and standardize outbound HTTP client creation across Franz-based applications.
- Leverage Franz primitives (
MediatorContext, correlation IDs, and shared Polly registry). - Ensure all external calls are traceable, resilient, and predictable out of the box.
- Maintain a minimal public API surface while delivering production-grade ergonomics.
Features
Unified Client Registration
AddFranzRefit<TClient>(...)— single-line registration that configures:- Base URL
- Correlation & tenant headers
- Authentication (optional)
- Polly resilience policy
- OpenTelemetry enrichment
Header Propagation
FranzRefitHeadersHandlerautomatically injects:X-Correlation-IDX-Tenant-IdX-User-Id(if available)
Authentication Handler
FranzRefitAuthHandlerintegrates via a pluggableITokenProvider. Automatically disables itself if no provider or options are configured.Resilience Integration Seamless
Pollypolicy attachment viaAddPolicyHandlerFromRegistry.Telemetry and Metrics
- Annotates
Activity.Currentwithfranz.http.*tags for distributed tracing. - Lightweight internal
System.Diagnostics.Metrics(Meter:Franz.Refit).
- Annotates
Dependencies
- Refit.HttpClientFactory (8.2.0) — Refit integration with
IHttpClientFactory. - Microsoft.Extensions.Http.Polly (8.1.2) — HTTP-level resilience policies.
- Serilog (8.0.0) — Structured log correlation.
- OpenTelemetry.Api (1.8.1) — Distributed tracing support.
- Polly (8.1.2) — Retry, circuit-breaker, and fallback strategies.
Installation
From Private Azure Feed
dotnet nuget add source "https://your-private-feed-url" \
--name "AzurePrivateFeed" \
--username "YourAzureUsername" \
--password "YourAzurePassword" \
--store-password-in-clear-text
Install the package:
dotnet add package Franz.Common.Http.Refit
Usage
1. Register a Refit Client
using Franz.Common.Http.Refit.Extensions;
builder.Services.AddFranzRefit<IMyExternalApi>(
name: "MyApi",
baseUrl: "https://api.example.com",
policyName: "standard-http-retry",
configureOptions: opt =>
{
opt.EnableOpenTelemetry = true;
opt.DefaultPolicyName = "standard-http-retry";
opt.Timeout = TimeSpan.FromSeconds(30);
});
✅ Automatically configures:
- Correlation & tenant headers (
FranzRefitHeadersHandler) - Authentication (via
FranzRefitAuthHandler, optional) - Named Polly policy (from registry)
- OpenTelemetry tagging (if enabled)
2. Authentication (Optional)
Implement a token provider:
using Franz.Common.Http.Refit.Contracts;
public sealed class MyTokenProvider : ITokenProvider
{
public Task<string?> GetTokenAsync(CancellationToken ct = default)
{
// Fetch from secure store, cache, or identity service
return Task.FromResult("example-token");
}
}
Register it in DI:
builder.Services.AddSingleton<ITokenProvider, MyTokenProvider>();
If no ITokenProvider is registered, the handler auto-disables and no Authorization header is sent.
3. Configuration via appsettings.json
{
"RefitClientOptions": {
"EnableOpenTelemetry": true,
"DefaultPolicyName": "standard-http-retry",
"Timeout": "00:00:30"
}
}
Wire configuration:
builder.Services.AddFranzRefit<IMyApi>(
name: "MyApi",
baseUrl: builder.Configuration["ExternalApi:BaseUrl"]!,
configureOptions: opt =>
{
builder.Configuration.GetSection("RefitClientOptions").Bind(opt);
});
4. Example Resilience Policy Registration
using Polly;
using Polly.Extensions.Http;
builder.Services.AddPolicyRegistry(registry =>
{
registry.Add("standard-http-retry", HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
.WaitAndRetryAsync(3, retry => TimeSpan.FromSeconds(Math.Pow(2, retry))));
});
5. Example Typed Client Interface
using Refit;
using System.Threading.Tasks;
public interface IBooksApi
{
[Get("/books")]
Task<ApiResponse<List<BookDto>>> GetBooksAsync();
}
6. DefaultTokenProvider Example (OAuth2)
using Franz.Common.Http.Refit.Handlers;
using Microsoft.Extensions.Options;
builder.Services.Configure<DefaultTokenProviderOptions>(builder.Configuration.GetSection("Auth"));
builder.Services.AddHttpClient(nameof(DefaultTokenProvider));
builder.Services.AddSingleton<ITokenProvider, DefaultTokenProvider>();
Example Auth configuration:
{
"Auth": {
"TokenEndpoint": "https://login.example.com/oauth2/token",
"ClientId": "my-client",
"ClientSecret": "my-secret",
"Scope": "api.read"
}
}
This enables a cached OAuth2 token provider without any custom code.
appsettings (Bootstrapper)
If Franz.Common.Http.Bootstrap is active and Franz:HttpClients:EnableRefit = true,
Refit clients can be registered automatically from configuration:
{
"Franz": {
"HttpClients": {
"EnableRefit": true,
"Apis": {
"Books": {
"InterfaceType": "MyApp.ApiClients.IBooksApi, MyApp",
"BaseUrl": "https://api.example.com",
"Policy": "standard-http-retry"
}
}
}
}
}
Changelog
Franz 1.6.17 — Refit Overhaul & Self-Healing Auth
🔹 Highlights
Self-Disabling Authentication Handler
FranzRefitAuthHandlernow auto-deactivates when no token provider or configuration is present.
Unified Refit Registration
- Simplified
AddFranzRefit<TClient>()registration combining Refit setup, Polly, OTEL, and Serilog context propagation.
- Simplified
Improved Token Provider Contract
ITokenProviderfully async, nullable token support, integrated fallback provider.
OpenTelemetry Support
- Native tag injection with
franz.http.*naming convention.
- Native tag injection with
Config Binding
- Direct JSON binding for
RefitClientOptions(e.g.,Timeout,DefaultPolicyName).
- Direct JSON binding for
Default Token Provider
- New optional
DefaultTokenProviderwith client credentials OAuth2 flow support.
- New optional
Better Sandbox Behavior
- Auto-switch to
NoOpTokenProviderwhen authentication is not required.
- Auto-switch to
Integration with Franz Framework
- Franz.Common.Mediator — shares correlation and policy context.
- Franz.Common.Logging — consistent logging with correlation IDs.
- Franz.Common.Http.Client — same conventions for non-Refit clients.
Together, they provide a fully coherent HTTP and API integration ecosystem under Franz.
Contributing
This package is internal to the Franz Framework. If you have repository access:
- Clone:
https://github.com/bestacio89/Franz.Common/ - Branch from
develop. - Submit a PR with changelog updates and semantic version bump.
License
Licensed under the MIT License (see LICENSE file).
Best Practices
| Scenario | Recommendation |
|---|---|
| No Auth / Sandbox | Do not register ITokenProvider; auth handler disables automatically. |
| Auth APIs | Register ITokenProvider or use DefaultTokenProvider. |
| Resilient APIs | Use Polly policies from the global registry. |
| Observability | Enable OpenTelemetry tagging and use Serilog for structured logs. |
| Configuration | Prefer JSON-bound RefitClientOptions for consistency. |
| 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
- Franz.Common.Mediator (>= 1.7.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- Microsoft.Extensions.Http.Polly (>= 10.0.0)
- Microsoft.Rest.ClientRuntime (>= 2.3.24)
- OpenTelemetry.Api (>= 1.14.0)
- Polly (>= 8.6.5)
- 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 |