Franz.Common.Http.Refit 1.7.1

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.7.1
                    
NuGet\Install-Package Franz.Common.Http.Refit -Version 1.7.1
                    
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.7.1" />
                    
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.7.1" />
                    
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.7.1
                    
#r "nuget: Franz.Common.Http.Refit, 1.7.1"
                    
#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.7.1
                    
#: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.7.1
                    
Install as a Cake Addin
#tool nuget:?package=Franz.Common.Http.Refit&version=1.7.1
                    
Install as a Cake Tool

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 FranzRefitHeadersHandler automatically injects:

    • X-Correlation-ID
    • X-Tenant-Id
    • X-User-Id (if available)
  • Authentication Handler FranzRefitAuthHandler integrates via a pluggable ITokenProvider. Automatically disables itself if no provider or options are configured.

  • Resilience Integration Seamless Polly policy attachment via AddPolicyHandlerFromRegistry.

  • Telemetry and Metrics

    • Annotates Activity.Current with franz.http.* tags for distributed tracing.
    • Lightweight internal System.Diagnostics.Metrics (Meter: Franz.Refit).

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

    • FranzRefitAuthHandler now 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.
  • Improved Token Provider Contract

    • ITokenProvider fully async, nullable token support, integrated fallback provider.
  • OpenTelemetry Support

    • Native tag injection with franz.http.* naming convention.
  • Config Binding

    • Direct JSON binding for RefitClientOptions (e.g., Timeout, DefaultPolicyName).
  • Default Token Provider

    • New optional DefaultTokenProvider with client credentials OAuth2 flow support.
  • Better Sandbox Behavior

    • Auto-switch to NoOpTokenProvider when authentication is not required.

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:

  1. Clone: https://github.com/bestacio89/Franz.Common/
  2. Branch from develop.
  3. 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 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
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