Guide - Web Programming with F#
F# excels at building efficient, scalable and robust web solutions. Web programming is based around receiving a single HTTP request and replying with a result, which maps very well to a stateless, functional approach. Advantages to using F# for web programming include:
-
Fast - F# code execution is fast, using native code generation from scripted or project code
-
Succinct - F# is concise, readable and type-safe, for fast development of robust web solutions
-
Reactive and Scalable - F# asynchronous programming simplifies scalable, reactive web programming
-
Interoperable - F# interoperates seamlessly with languages such as C#, JavaScript and TypeScript
-
JavaScript-ready - F# is JavaScript-ready through WebSharper and Fable
-
Open-source and cross-platform
To contribute to this guide edit this page. These resources are for educational purposes.
- Integrated Stacks
- Web Frameworks
- Web Testing Frameworks
- Live Examples
- Tutorials
- Books
- Presentations
- Hosting
Integrated Stacks
SAFE Stack
SAFE Stack is an end-to-end, functional-first stack for cloud-ready web development that emphasizes type-safe programming. It is an application development stack that brings several technologies together into a single, coherent stack for type-safe, flexible, web-enabled applications that can be written almost entirely in F#.
WebSharper
WebSharper allows end-to-end web applications with both client and server developed in F#. It includes TypeScript interoperability, mobile web apps, getting started material, templates and much more.
Fable
Fable is an F# to JS compiler designed to generate clean and standard code in order to maximize interoperability in both ways. It integrates with most of JS development pipelines like Babel, Webpack or React Hot Loader. Fable allows you to develop node.js services, desktop apps with Electron and mobile apps with React native.
Web Frameworks
Giraffe
Giraffe is an F# library for building rich web applications that use ASP.NET Core under the hood. It has been heavily inspired and is similar to Suave, but has been specifically designed with ASP.NET Core in mind and can be plugged into the ASP.NET Core pipeline via middleware.
ASP.NET Core
ASP.NET Core is a modern, cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. It runs on .NET Core and supports F# out of the box. If you install the .NET Core SDK, there are F# templates available via the dotnet new
command.
Suave
Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.
Saturn
Saturn is a web development framework written in F# which implements the server-side MVC pattern. Many of its components and concepts will seem familiar to anyone with experience in other web frameworks like Ruby on Rails or Python’s Django. It’s built on top of Giraffe and ASP.Net Core - modern, cross-platform, high-performance development platform for building cloud-ready web applications.
It’s heavily inspired by Elixir’s Phoenix.
Bolero
Bolero - F# on the client side, no JavaScript - Bolero uses Blazor to bring F# to WebAssembly. Create dynamic HTML content using syntax familiar from WebSharper and Fable, in a full-fledged client-side .NET web framework.
Falco
Falco is a functional-first toolkit for building brilliant ASP.NET Core applications using F#. It is built upon the high-performance primitives of ASP.NET Core, optimized for building HTTP applications quickly, and seamlessly integrates with existing .NET Core middleware and frameworks.
ServiceStack
ServiceStack is a framework for simple and fast web services on .NET.
Web Testing Frameworks
Canopy for Client-side Testing
canopy is a web testing framework built on top of selenium and written in F#. It’s syntax is clean and concise. You can easily leverage your existing .NET code to help you test.
Unit Testing Libraries
Some open source libraries that assist with web unit testing are:
Live Examples
TodoBackend
TodoBackend is a project that aims to be “a shared example to showcase backend tech stacks.” The F# community has contributed some examples, and a few more are in progress:
Please consider contributing, either directly to the TodoBackend project or via the TodoBackendFSharp project.
Tutorials
- Suave Music Store Tutorial for creating applications with Suave.IO
Books
Several books have been written that include information on building web applications with F#:
Presentations
There are several presentations and tutorials available that include information on build web applications with F#:
Hosting
Common hosting options are:
-
Heroku - See, for example, F#, ServiceStack and Heroku and complete article about hosting NancyFx and F# on Heroku
-
Azure Web Sites - Create and deploy to free Azure web sites from Visual Studio and other tools
-
AppHarbor - Free hosting of .NET web applications
-
GearHost - Free hosting of .NET web applications (100 MB), IIS based, support for both .NET Framework and Core, MSSQL and MySQL databases (10 MB), support of simple WebJobs.