F# is excellent for building scalable, robust web solutions:
- Fast and Scalable - F# is much faster than NodeJS, Python, PHP and Ruby
- Succinct - F# is concise, readable and type-safe, for fast development of robust web solutions
- Asynchronous - F# provides asynchronous programming to simplify scalable client-server programming
- Open-source and Cross-platform - Like all good web tools!
Frameworks for Web Applications
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.
NancyFx is a lightweight, low-ceremony, framework for building HTTP based services on .NET and Mono. F# templates are available.
Frameworks for Server-Side Web APIs
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#.
Some resources on using F# with Web API:
F#/C# Web Templates for REST - (Visual Studio, ASP.NET Web API) Includes templates for ASP.NET Web API.
Frank provides a functional wrapper around the types in System.Net.Http, the library that drives ASP.NET Web API.
ServiceStack is a framework for simple and fast web services on .NET and Mono.
F# ServiceStack Project Template - (Visual Studio) Includes a template to create a self-hosted, Asp.Net hosted F# ServiceStack service
F# and ServiceStack Example 1 - Web Services on any platform in and out of a web server! An async+parallel cached twitter proxy that works cross platform on Windows/OSX and Linux in 100 LOC
F# and ServiceStack Example 2 - An Async, Cached Twitter API Proxy in F#
F#, ServiceStack and Heroku - Using ServiceStack and Heroku with F#
Simple.Web is a REST-focused, object-oriented Web Framework for .NET
- Pure F# Simple.Web Template - (Visual Studio) Includes a template for getting started with Simple.Web.
Serving Requests with IHttpHandlers
Do it the simple way, and serve web requests direct from code using F# asynchronous programming.
Making WSDL Services
- F#/C# Web Service Template for WSDL - (Visual Studio, ASP.NET) Includes a template for WCF.
Common hosting options are:
- Heroku - See, for example, F#, ServiceStack and 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
Scaling to the Cloud
The Cloud Programming section contains more details on cloud programming with F#. Some specific resources related to web programming are:
- F# 3.0 Azure Samples
- How to Create a Cloud-Scalable Internet Game Using F#, C#, and ASP.NET
- Using F# and C# with Amazon EC2 Elastic Map/Reduce
Unit Testing Libraries
It is common to create a suite of unit tests when building web solutions. A list of open source libraries that assist with unit testing is available here:
Here are a few Visual Studio project templates available for building unit tests:
- 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.
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#:
Older ASP.NET MVC using two projects (one F#, one C#)
When using MVC ASP.NET 3 or 4, mixed C#/F# ASP.NET MVC are used. In this approach, views are implemented in HTML with some C#. Models and controllers are implemented in F#.
The F#/C# Web Templates (Visual Studio, ASP.NET MVC 4)
include templates for ASP.NET MVC 4 (ASPX/Razor) and Single Page Applications with Backbone.js or Knockout.js.
The F#/C# Web Templates (Xamarin Studio, ASP.NET MVC 4) are a similar set of cross-platform templates for MonoDevelop.
The F#/C# Web Templates (Visual Studio, ASP.NET MVC 3 include templates for ASP.NET MVC 3 (ASPX/Razor).
For those still using Silverlight, you can use F# to build Silverlight projects in whole or in part. Some resources are:
- F# Client-Side Application Template (Visual Studio, Silverlight) - Includes a simple template for creating F# Silverlight Applications. The template creates a single Silverlight project that creates Silverlight controls from F# code and runs in an automatically generated HTML page.
- F# Web Application Template (Silverlight) Includes a template for Silverlight 4 and 5.