0

I have a class that includes a Uri instance. The class is sent as an argument to REST api

[Serializable]
public class SomeClass
{
    public Uri Uri { get; set; }
}

public interface IRefitExample
{       
    [Post("/api/example")]
    Task<string> Example(SomeClass someClass);
}

For some reason the Uri object does not pass correctly with refit.
The Uri absolute url string looks like this on the client side:
"file:///var/share"
When it reach to the server it looks like this:
"/var/share"

The refit initialization looks like this:

var settings = new RefitSettings(new NewtonsoftJsonContentSerializer());
            _apiRefit = RestService.For<ISomeApi>($"http://localhost:5000", settings);

Thanks.

Ohad Horesh
  • 4,340
  • 6
  • 28
  • 45

1 Answers1

1

Maybe i don't understand the problem right but there is no problem with Refit. In your RefitSettings you use NewtonsoftJsonContentSerializer() which serealize Uri object due to ISerializable interface implementaion and pass json like this: {"Uri":"file:///var/share"} into http request body.

File URI has next format: file://host/path. If host is omitted, it is taken to be "localhost", the machine from which the URL is being interpreted. Note that when omitting host, the slash is not omitted (while "file:///foo.txt" is valid, "file://foo.txt" is not, although some interpreters manage to handle the latter).

So URI from your example points to the following path ./var/share (which is the same as /var/share) on local machine.

This links can be helpful:

Repulse3
  • 108
  • 6