Skip to content

feature: per-type IUrlParameterFormatter registry on RefitSettings #2219

Closed

Description

@glennawatson

Summary

Follow-up to #2046. Round-tripping, path, and query parameter values of any type are currently formatted through a single IUrlParameterFormatter (falling back to ToString()). To customize how one specific CLR type is rendered into a URL you must implement a custom IUrlParameterFormatter that switches on the value's Type for every call.

A per-type formatter registry on RefitSettings would make per-type URL formatting ergonomic - register a formatter (or a Func) keyed by Type, consulted before the default formatter - without hand-rolling a type switch.

Proposal

  • Add a way to register a URL-parameter formatter for a specific CLR type on RefitSettings (for example a Type-keyed map of formatting delegates).
  • The registry is consulted first; when no entry matches, the existing IUrlParameterFormatter / default behavior applies.
  • Keep it delegate-based (no reflection / no dynamic code) so both the reflection and source-generated paths stay AOT/trim-safe.

Acceptance criteria

  • A formatter can be registered for a specific type and is used for path and query values of that type.
  • Falls back to the current default formatter when no per-type entry matches.
  • Populated/consulted identically in both the reflection and source-generated paths.
  • Documented in the README with a short example, and covered by tests in both paths.

Pointers

  • src/Refit/RefitSettings.cs (UrlParameterFormatter).
  • Path/query rendering: src/Refit.Reflection/RequestBuilderImplementation.RequestBuilding.cs and the generated equivalents in src/Refit/GeneratedRequestRunner.cs.

Activity

  1. added
    🔗 area: url-routing
    on Jul 14, 2026
  2. glennawatson commented on Jul 15, 2026

    @glennawatson
    ContributorAuthor

    This is addressed in the Refit 14 beta, now available on NuGet: https://www.nuget.org/packages/Refit/14.0.0-beta.1

    Please give it a try - feedback ahead of the stable 14.0.0 release is very welcome.

    Type-safe REST API clients for .NET, generated from annotated interfaces with build-time source generation, direct request construction, System.Text.Json defaults, and support for trimming and AOT.
  3. github-actions commented on Jul 30, 2026

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  4. locked as resolved and limited conversation to collaborators on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ enhancement🔗 area: url-routing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions