Creating Web Applications

Ody Mbegbu
Real World F#
Published in
3 min readSep 15, 2016

This is part of the Series: “Building Real-World Applications in F#”

Using F# to create small Web Applications is great and you have a slew of frameworks to pick from. Like Suave, WebSharper and even the regular dotnet frameworks like Nancy and of course ASP.NET work pretty well with F# and for the last two, Microsoft has provided Visual Studio templates for them. but they aren’t exactly F# friendly.

“So why don’t you try some of the F# friendly frameworks?”

I tried to use the other Web Frameworks like WebSharper and Suave and they are lovely frameworks.. But my problem with them is that don’t exactly embrace the Web. Suave has its own DSL for building html pages which works but essentially abstracts the creation of the actual HTML. WebSharper on the other hand attempts to kill both server side code and client side code with one stone. *cough* meteor.js *cough*. In theory, I could plug the Razor Engine into Suave.io but that seems like a lot of work but I’ll investigate it later and possibly write a library or plugin for it. The underlying principle of abstracting HTML means that leveraging existing templates or working with designers becomes challenging.

“Okay, So why not use the existing frameworks from F#”

Well.. here’s the thing. When you need to create or port an Application that has hundreds of pages, You quickly run into a problem. The fsproj file format mixes compilable and non-compilable assets in the same section which means that if you include something like Bower and install client-side libraries like angular, aurelia and co, it becomes really difficult to manage. In fact, when your application has a sizable number of nested files in VS, you’ll be fighting with VS to manage them and you’d be constantly editing the fsproj files.

The good news is that this issue is non-existent with the new ASP.NET Core as you only need to include compilable files in your project.json and all other files show up in VS. but at the moment, F# tooling for dotnet core is still in preview.

The bad news is that doing modern web applications with client side frameworks like Bower, Typescript, Angular etc is a pain in Visual Studio using F#. And after trying to use both Visual Studio and Visual Studio Code to edit the same project, I gave up.

“So what next?”

Well, the era of server side rendered web applications are coming to an end. They will still exist for some web applications that need to be public because of Search Engines but the majority off applications in the future will deal with the browser as just another Client.

I’ve decided to use an empty ASP.NET Web Application :( to create this client . It just houses all of the client side templates and Javascript Code. Nothing more. The real party will be in the Web API layer. the only C# code in it will be the AssemblyInfo.cs I think I can live with that.

Here’s what the project structure looks like at the moment. Will be updating it in the coming weeks

Project Structure

--

--