Current state of Web Programming in F#
There was a time nothing much happening in Web in regards of F. It was treated as general purpose language for something you can use to do batch jobs, back end tasks.
As far as I remember I never felt issue in using F# library in C# or vice verse. Obviously there were always a problems to make things work and my initial F# questions on Stack Overflow were mostly about inter-portability. But at the end of day in most of the cases it works without much of an issue. Today is different and we will going to talk about current state of F# for Web programming.
Just to give you a gist, F# was never a Mathematician’s, Data Scientist’s only language but now it is showing that it is as general purpose as any other language if not more.
I never wanted to include this section. But as written by George Santayana ***“Those who cannot remember the past are condemned to repeat it.”; ***I have put this section in article. This article is nothing but telling everyone that I am getting old now. It is bit of F# history and my history with F#.
Intro to F#
My introduction to F# is kind of because I wanted to learn how things work if I want to develop something related to finance. One thing led to another and I started learning F# using **tryfsharp. **Good old days of Silverlight. At that time Visual Studio not officially supporting F#. You need to install tools separately and install it for F# support. Forget about any other template. I don’t even remember there were much people using it. I distinctly remember Tomas, Evelina, Don and few more. As my most of the experience in Web, at that time also I wanted to use F# in Web Programming. I was using it by adding separate library project of F# in C# Web Project; it did work. But still something was missing. A complete F# Web Project.
F# on Heroku
I was able to run F# web application (self host using ServiceStack ) on Heroku back in days. It was listed under official guide for F# for web programming. My first bit of glory in F# world. I did spend couple of sleepless night to run that. And when it runs it was pure aha moment. I never got that much excited after that.
That was year 2013. You can still find the code here. It is old code but it works and served as a reference for a long time. Now, F# org site is going under a make over; I hope it stays in new site as well, as historical monument.
This was the time when one has to play with GUIDs if they want pure F# web application. I did added my bits to make this thing easier via creating templates for Web Application for Visual Studio 2012 and 2013. We do have templates for all the web framework available in Dot Net Full Framework. And yes there was no *dot net core . *Even though we still make things working on Azure with Kudu deployment.
Yes, I have been doing F# even before VSCode and Ionide , before paket and Fake was popular and way before Fable was there. Sometimes I do miss good old days of fixing Visual Studio and fsproj file.
Always a Hero
Even though things are not good enough, F# was always a hero. It works and it works way better.
Same thing with ServiceStack and SignalR. Code looks way better in this. But still people were not picking up as option.
Until this time around when effort to bring F# to web increased multi-fold.
Web and F# — Right Now
Oldest F# specific project to write F# on client and server side. It comes with commercial support and it is super awesome, always has been. Let’s see simple example of it.
ServiceStack with F#
ServiceStack is one of the most favorite web framework in early days to write API with F#. V3 is still available for free while V4 is now comes with commercial license. But this is one of the best framework I have worked with. Very much natural fit to functional language like F#. I can tell that after working with plenty of .Net web framework including WCF. It works with dotnet core, have plugins for almost everything and anything. It also has light weight ORM called **OrmLite. **And that too; works with F# without any issue. It is my personal favorite for production projects. Let’s see the code.
NancyFx with F#
Whenever I want to write sweet code with C#, NancyFx was and is always and first choice. Things become sweeter when it comes to F#. Here is Hello World from NancyFx.
ASP.Net MVC and Web API
Asp.Net MVC and Web API worked with F# since their inception. And it worked without more of any issue because of F#’s great support of CLR and OOP side of it. At the max sometimes just to make tooling happy we need to keep C# project around as wrapper and push client related stuff like JS, CSS and Razor in C# project and other things can be moved to F# project. Dot Net Core and Dot Net Core project templates have made things even more easier for getting started with F#.
I will skip those sample as F# community is kind having love — hate relationship with Microsoft Backed projects.
Above all are C# web frameworks, which holds the fort till new F# specific framework comes on horizon.
Suave is first one in town. First F# specific framework, with its own server implementation; if my memory serves me right. Just like Nancy it was micro framework and one can get up and running in minimum possible code. Let’s have a look at code.
When dot net core arrived. It was natural to have F# code that works on asp net core. But Giraffe goes one step ahead with wrapper that makes natural to write F# code on top of asp net core.
Freya take different approach then above two as web framework. It is composition based concurrent framework. Here you start creating *machines *that takes care of executing requests. Have a look at below code. Understanding Freya in details is definitely out of scope for this article so may be next time.
I have always missed RoR like web framework. Asp.net MVC was there but never gave quite a feel. After phoenix came to Elixir, I wanted something for F# too. And then one fine night, I did see Saturn in sky. It is traditional MVC framework build on top of Giraffe. It comes with batteries (generators). Definitely a choice for some old school projects. Have a look at the code.
Fable is best thing happen to F# after F# it self.
We did come a long way ahead, and I was lucky enough to be part of it. Currently F# works on Dot Net Full Framework and Dot Net Core. Visual Studio and Visual Studio for Mac supports it by default. VS Code, Atom, Vim and other editors supports via plugins. You can build not only back end but beautiful front end using F#.
Every technology have their abbreviation stack. It is basically combination of different technologies. So, how can F# stays behind. SAFE is same thing, combination of different technology to achieve one single goal; *build a web application *using F# everywhere. Have a look at how to start with SAFE stack and different option we have in SAFE template.
After working in different technology for front end, back end, mobile, IOT and Cloud etc. I finally decided branch out. I have been consulting on F# project for last year as day job. So, after closing that I am / we are ready for new assignment. At Fuzzy Cloud we are happy to assist you for F#, Type Script, Front End, Back End, Cloud related projects. Be it Green Field or Brown Field. Just drop a message and we can talk about it.
We are officially supporting SAFE stack, along with two other wonderful consultancy.
Love to here from you. Happy Coding.