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
- Open-source and cross-platform
The Cloud Programming section contains more details on scalable cloud-hosted web programming with F#.
To contribute to tooling for F# web programming, please join the F# Web Stack Google Group.
To contribute to this guide, edit this page on GitHub.
The resources listed below are provided for educational purposes related to the F# programming language. The F# Software Foundation does not endorse or recommend any specific commercial products, processes, or services
Resources for Web Programming
- Resources for Web Programming
- Frameworks for Web Applications
- Frameworks for Micro-services and Server-Side Web APIs
- Live Examples
- Unit Testing Libraries
Frameworks for Web Applications
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.
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 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.
NancyFx is a lightweight, low-ceremony framework for building HTTP-based micro-applications and micro-services on .NET and Mono. F# templates are available.
Frameworks for Micro-services and Server-Side Web APIs
Do it the simple way, and serve web requests direct from code using F# asynchronous programming.
- F# async on the server side - Non-blocking I/O on the server side
Suave can be used for microservices in addition to serving web content.
Web API 2.0 is a widely used open source web framework from Microsoft. The Pure F# Web Templates (Visual Studio, Web API 2.0). These templates provide a Pure F# project for implementing a web API with Web API 2.0. Everything is implemented in F#.
OWIN and Katana provide a flexible set of components for building and hosting Open Web Interface for .NET (OWIN)-based web applications. Web API can be hosted directly on Katana using the Owin Web API package.
Some resources on using F# with Web API:
- Visual Studio templates
- How to create a pure F# ASP.NET Web API project
- Running a pure F# ASP.NET Web API on Azure Web Sites
- Creating Lightweight F# websites that use pure F# OWIN Web APIs and Typescript web applications
- Sample F# ASP.NET Web API hosted with OWIN on an Azure Worker Role
- F#/C# Web Templates for REST - (Visual Studio) Includes templates for ASP.NET Web API.
- A Simple Nowin F# Example - example showing an F# OWIN app running on a web server other than IIS.
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.
Freya provides a functional web stack built on top of OWIN. At its core, Freya wraps the OWIN environment dictionary with a computation expression and provides access to that dictionary with lenses. Additional layers of the stack provide types based on the HTTP and related RFCs, a pipeline abstraction for connecting Freya computations, a router, and an implementation of the HTTP finite state machine, like that found in webmachine.
Frank provides combinators for composing web applications using the types in
System.Net.Http, the library that drives ASP.NET Web API.
SignalR provides bi-directional communication between web servers and clients using one of several mechanisms, beginning with web sockets and falling back through several other approaches depending on client and server capabilities. One example is a Web Application Server (F#).
- Skillscast: F# and SignalR for a fast Web
- F# and SignalR Stock Ticker part 1 part 2
- StackOverflow answer demonstrating typed access to SignalR client methods
ServiceStack is a framework for simple and fast web services on .NET and Mono.
NancyFx is a lightweight, low-ceremony framework for building HTTP-based micro-services on .NET and Mono.
- NancyFx Project Template Includes templates for for getting started with a range of NancyFx applications.
- F#, NancyFx and Heroku - Using NancyFx and Heroku with F#
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.
- Web Application Development in F# Using ASP.NET MVC
- Suave Music Store Tutorial for creating applications with Suave.IO
Several books have been written that include information on building web applications with F#:
There are several presentations and tutorials available that include information on build web applications with F#:
- Taking F# to the Masses with CloudSharper
- F# on the Web
- Tackle UI with Reactive DOM in F# and WebSharper
- Building an HTML5 application with WebSharper Sitelets, Part 1
- Building Better Web Apps with F#
- Building Data-Driven Websites
- F# on the Web Workshop
- F# 3.0: data, services, Web, cloud, at your fingertips
- F# Introduction
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
Unit Testing Libraries
Some open source libraries that assist with web unit testing are:
Here are a few Visual Studio project templates available for building unit tests: