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

.Net7 + Fable 4 + Giraffe + .NET HTTPClient #346

Closed zelenij closed 1 year ago

zelenij commented 1 year ago

I have a Fable app that uses Fable.Remoting. Among other things, it contains a few tests, that assess the server side via HTTP. Basically inside the test I submit some JSON via the standard System.Net.Http.HttpClient and then check the return JSON.

This worked pretty well with .NET6 + Fable 3. I didn't update any dependencies for close to a year. Now I have just upgraded everything to the latest Fable 4, Fable.Remoting, .NET7, Giraffe etc. After some tweaking everything seems to be working fine, including client/server communication from the browser. BUT the HttpClient tests all fail. It seems that something happens to the incoming JSON and it is all treated as having fields set to null.

Now, I doubt it is necessarily Fable.Remoting problem. Probably I'm doing something incorrectly. But I don't have a working theory at the moment. I added a print statement in my test code which serialises the objects to be sent with System.Text.Json.JsonSerializer.Serialize, which is what HttpClient seems to do. And the result looks indistinguishable from what I can see in the browser.

Any thoughts on how to address this?

Zaid-Ajaj commented 1 year ago

Hi @zelenij, I am not exactly sure why your HttpClient tests are failing but it is probably because we changed how a piece of JSON is serialized/deserialized and your HttpClient doesn't know how to work with the new shape of data. The remoting clients are usually updated to handle server-side changes under the hood as the JSON is an implementation detail for Fable.Remoting.

What I am wondering about is why you are using raw HttpClient to write tests when you can use Fable.Remoting.DotnetClient to talk to your backend from a dotnet client. If you use DotnetClient I assume it will understand the shape of the data from the remoting server.

zelenij commented 1 year ago

Well, this makes sense. I saw Fable.Remoting.DotnetClient, but for the life of me I couldn't figure out how to use it. Do you have a simple example please?

Zaid-Ajaj commented 1 year ago

Here you go https://zaid-ajaj.github.io/Fable.Remoting/#/client-setup/dotnet

zelenij commented 1 year ago

OK, thanks! Seems to be working. Now I need to update all those tests :)

Zaid-Ajaj commented 1 year ago

Glad to hear that it is working 😄 will go ahead and close the issue. Feel free to open another one if you have any questions