Skip to content

fsharp

Websharper super power with Vars

#WebSharper’s super power with Vars Using WebSharper allows you to develop both the client side and the server side of a web application in C# or F#, with client to server communication abstracted as RPC calls. There’s no need to handle low-level concerns like XMLHttpRequest or data serialisation. There’s great Javascript interoperability of course, allowing to use javascript libraries from your F# code. But still, what I enjoy most when developing a WebSharper app is its reactive layer built on Vars and Views.

Manipulating javascript objects in FSharp with WebSharper

In a WebSharper app I’m using Bootstrap tooltips, and those need to be initialised explicitly. As shown in the doc this is easily done. For example this code will make the tooltip work as expected for the element with id elementId, so that hovering that element will trigger the tooltip to be shown: var el = document.getElementById(elementId) new bootstrap.Tooltip(el) However, in my case, the element for which a tooltip should be shown is dynamically added and removed from the document following user actions.

Websharper compilation problem after dotnet update

If you encounter problems compiling your WebSharper project after an update of your dotnet installation, you might have to restart the service wsfscservice. Under linux you can simply issue the command pkill wsfscservice. wsfscservice is used to speed up repeated compilation. As explained by Jand42:it uses AssemblyLoadContext for WS macros/offline site generator, but F# compiler part can sadly lock some dlls for TPs and it seems SDK update messes with it too.

Handling Large Uploads in Fsharp and ASP.Net Core

I found the documentation regarding handling large uploads in a ASP.Net Core app confusing. I didn’t find a lot of code examples, and even none at all using F#. Eventually I found an example I could get inspiration from and build a working solution with. It should work with whatever ASP.Net Core based framework you use, as long as you can get a handle on the Microsoft.AspNetCore.Http.HttpContext instance. You will need to clarify some things before you put the code in production.

Ddefine a f# function using reflection

#Intro I looked at this thinking it would be useful with WebSharper.Forms definition. I was wrong, but I want to keep a trace of this, so here is a blog post about it. This post is not meant to be pedagogical, but it can be useful as an example. We’ll work on an example DU type hypothetically used to describe form fields: type DataType = |String of name:string |Int of name:string |Choice of name:string * string list You can use this type to define forms.

Websharper Proxy Project

WebSharper lets you bring your FSharp code to the client-side. For types in your WebSharper project to be used at both server and client sides, you annotate them with [<JavaScript>]. For types that were compiled without WebSharper, you need to define a proxy type, which will be compiled to javascript and be used in place of the compiled type. This is done easily, as this example from the official documentation shows:

Sending Mails In Aspnetcore

This post is part of series starting here. Here’s how I configure my mailers in a ASP.Net Core project developed in F#. I define an interface: type IMailer = // to * subject * body abstract Send: string * string * string -> unit of which I have 2 implementation. The first one is for development as it simply prints the mail on the server’s standard output: type ConsoleMailer() = interface IMailer with member _.

Passwordless Login Sending Login Mail Websharper

This post is part of series starting here. Sending the mail Sending the mail is not hard, but will show how code running at the client side can call RPC functions provided by the server. These calls are totally transparent. For the login page, we add an endpoint: | [<EndPoint "/l">] Login and map it to a function all as seen earlier: Application.MultiPage (fun ctx endpoint -> match endpoint with | EndPoint.

Passwordless Login With Websharper

Intro I had the need recently to provide some admin access to a web application, but adding password management in that application was not worth the trouble. It was much easier to allow users to request a authentication link by email, as this post will show. The web app is dveloped in WebSharper. If you’re a F# developed, you should really check it out! I like that I can develop client and server in one integrated code base, all in F#.