Skip to content

Support non-string round-tripping parameters #2046

@rmja

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions