Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theoretical question: Client Library #3876

Closed
dcook-net opened this issue Aug 15, 2024 · 2 comments
Closed

Theoretical question: Client Library #3876

dcook-net opened this issue Aug 15, 2024 · 2 comments

Comments

@dcook-net
Copy link

Description

I have a web service that my team built and maintains, with various different endpoints.
We've also build a client library to encapsulate logic for talking to this service, which encapsulates things like authentication, caching, retries, etc....because we have serveral consuming services and we didn't want to duplicate that logic.

The library is built in .net and distributed over github.

Now we need to provide another client to our javascript and typescript consumers (including node).

I've been pondering the idea of re-writing the original .net client (originally c#) in F# and then generating the TypesScript and js with Fable, rather than having to build and maintain 2 versions.

I've only ever done very basic proof of concepts with Fable.
So my question, before I'm embark on such as task, is: do you think this is possible?

What challenges are we likely to encounter?

@MangelMaxime
Copy link
Member

Hello,

It should be possible to do. The main difficulty you can face is if you are using API not supported by Fable. You can see a summary of it here.

I also think the main difficulty you will face is if your library does HTTP call there is no support HttpClient library in Fable you will need to use compiler directives to make you .NET version use HttpClient and Fable/JavaScript version use fetch for example.

let getData () =
	async {
		#if FABLE_COMPILER
		// use fetch
		#else
		// use HttpClient
		#endif
	}

In your project you will probably create a small helper/library to make a common API between HttpClient/Fetch and don't have to worry about it in the rest of your project.

This blog post can also interest you I believe, it explains how they use Fable to support several targets like .NET, JavaScript, Python, etc.

@dcook-net
Copy link
Author

Thanks, this is great info, thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants