Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
272 stars 55 forks source link

Remoting.buildProxy in DotnetClient disregards path part of RemoteBuilderOptions.baseUri #344

Closed reinux closed 1 year ago

reinux commented 1 year ago

This line uses the Uri(Uri, string) constructor, which drops the path part of the first Uri.

let route = Uri(options.BaseUri, (routeBuilder t.Name param.Name).TrimStart('/')) |> string

Which means that doing something like the following:

let api =
  Fable.Remoting.DotnetClient.Remoting.createApi "http://localhost:9120/api"
  |> Fable.Remoting.DotnetClient.Remoting.buildProxy<XivApi>

the /api part goes missing.

Since this is how the System.Uri constructor is designed, I think the only solution would be to either construct the entire Uri manually from the base url parts, or to prepend the routeBuilder result with the path.

Zaid-Ajaj commented 1 year ago

Hi @reinux I believe if you need to append /api to your endpoint, you can use a custom route builder for it:

let routeBuilder (typeName: string) (methodName:string) = $"/api/{typeName}/{methodName}"

Can you give this a try?

reinux commented 1 year ago

Oh, duh, that did it.

I was looking for withBaseUrl, which exists in the Fable version but not the dotnet version. Should have noticed withRouteBuilder anyway though, since it exists for the server builder as well.

Thanks!