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
273 stars 55 forks source link

Add Fable.Remoting.NodeClient #225

Open sergey-tihon opened 3 years ago

sergey-tihon commented 3 years ago

Would be nice to have client library for Fable.Remoting that work in Node.js.

One of use cases is the communication with API from vscode extension written with Fable and hosted in a Node.js process in VS Code.

If/when someone decide to contribute client library for Node.js would be nice to have approved transport library.

What can be used instead of XMLHttpRequest for HTTP calls to be merged in this repo?

Should be one of low-lever fable-node modules (like HTTPS for example) or it can be some popular and lightweight http library like got (that is used in REST Client for example.

MangelMaxime commented 3 years ago

Hello, I think one of most popular http library is axios the minified version of the library is 15kb.

Zaid-Ajaj commented 3 years ago

Hi @sergey-tihon I always wanted a reason to have this implemented, now there is one 😄 as for the underlying HTTP client, the priority goes to the built-in client so that we have the least amount of dependencies unless other 3rd-party libraries make our lives easier.

I can't promise a timeline for this but I do want to have it at some point as part of the stack. PRs are always welcome of course 💯

sergey-tihon commented 3 years ago

@MangelMaxime axios looks interesting, because it works inside nodejs process and in the browser.

@Zaid-Ajaj is it an option to port fable client on top of axios? Or 15kb is a large footprint and you prefer to have separate package for nodejs?

Zaid-Ajaj commented 3 years ago

15kb is a large footprint

The size is not so much the problem here but the fact that users have to remember to install another package in order to use Fable.Remoting.Client which I would rather avoid.

sergey-tihon commented 3 years ago

For my use case I implemented API client for Node.js manually https://github.com/sergey-tihon/vscode-openxml-explorer/blob/main/src/extension/Remoting.fs

on top of Fable.Axios updated to Fable 3 https://github.com/sergey-tihon/vscode-openxml-explorer/blob/main/src/extension/Fable.Axios.fs

and opened issues to update Fable.Axios NuGet package.

Zaid-Ajaj commented 3 years ago

if that works for you then all good but just keep in mind that writing axios.post<Document> won't perform proper deserialization and is just saying "please treat this as if it was a Document" so if you have complex fields in your Document type such as unions or maps, they might not really work

sergey-tihon commented 3 years ago

ok, thank you, I all take a look at proper deserialization (when it breaks 😉 )

Zaid-Ajaj commented 3 years ago

Fable.Remoting.Client uses Fable.SimpleJson for JSON handling and deserialization and it should on nodejs without any dependency

Darkle commented 1 year ago

+1 for this. I am writing a service that needs to use a nodejs library, so I'm doing this with fable and the api is using fable remoting, so I would love to have a fable remoting nodejs library.