Skip to content

Support non-string round-tripping parameters #2046

Closed

Description

@rmja

Is your feature request related to a problem? Please describe.

I have several "string wrapper" record structs for which the value contains a / which I would like to be part of the generated url. It seems from:

https://github.com/reactiveui/refit/blob/main/Refit/RestMethodInfo.cs#L319-L324

that the only supported parameter type supporting the "Round-tripping" ** syntax is string.

What I want is something like:

public interface IApi
{
    [Get("/{**repo}/users/{id}")]
    Task<User> GetUserAsync(Repository repo, int id);
}

(either with or without the **)

Repository is a record struct that has a string in the some/repo format, that is with a / that I do not want to be url encoded.

Describe the solution you'd like

I can see three solutions (maybe there are more).

  1. Simply allow any type to by round-tripping, and call ToString() on it.
  2. Allow to somehow register the type Repository in RefitSettings and have an explicit formatter associated with it.
  3. Make it possible using the current IUrlParameterFormatter to return the raw string somehow. Currently the IUrlParameterFormatter is not invoked when the parameter is part of the path.

Describe alternatives you've considered

None

Describe suggestions on how to achieve the feature

None

Additional context

None

Activity

  1. added
    🟢 priority: low
    🔗 area: url-routing
    on Jun 16, 2026
  2. glennawatson commented on Jul 14, 2026

    @glennawatson
    Contributor

    Resolved on main by the reflection-free request-building refactor (#2210), so closing as fixed.

    • Round-tripping path parameters now accept any type, not just string. The value is rendered with IUrlParameterFormatter / ToString() and the / separators in the result are preserved segment-by-segment.
    • This works identically in both the reflection path and the source-generated path.
    • Verified by RestServiceExceptions.RoundTripParameterNotStringFormatsAndPreservesSlashes, which uses the exact reported shape (a readonly record struct RepoPath("some/repo") producing /repos/some/repo/contents), plus RoundTripNotStringGeneratedMatchesReflection asserting the generated output matches the reflection output.
    • The earlier premise that IUrlParameterFormatter is not invoked for path values is also no longer true; the formatter is now called for path parameters, object-property fragments, and round-trip segments.

    If you specifically want a per-type formatter registry configured on RefitSettings (rather than a custom IUrlParameterFormatter that switches on the value type), that is a separate enhancement - please open a new issue for it.

  3. glennawatson commented on Jul 14, 2026

    @glennawatson
    Contributor

    Opened #2219 to track the optional follow-up: a per-type IUrlParameterFormatter registry on RefitSettings, so custom URL formatting for a specific type does not require a hand-rolled type switch in a custom formatter.

  4. glennawatson commented on Jul 15, 2026

    @glennawatson
    Contributor

    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.
  5. rmja commented on Jul 20, 2026

    @rmja
    ContributorAuthor

    This seems to works just fine, thank you!

  6. github-actions commented on Aug 4, 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.

  7. locked as resolved and limited conversation to collaborators on Aug 4, 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🟢 priority: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions