Lesson 37. Exposing data over HTTP

 

In this lesson, you’ll look at ways to create HTTP-enabled APIs by using F# on the .NET platform. First, you’ll do this by using the well-known Microsoft ASP .NET framework, using the Web API component; you’ll then move on to looking at an alternative web technology, Suave. You’ll learn about

  • Working with the ASP .NET Web API and F#
  • Reasoning about HTTP response codes in F#
  • Working with Async and ASP .NET
  • Using Suave, an F#-first web application model

37.1. Getting up and running with the ASP .NET Web API

Let’s jump straight into this lesson and dispel any fears that your ASP .NET applications are somehow not compatible with F# by creating an ASP .NET application, in F#! You’ll look at two hosting mechanisms: web projects and console apps.

37.1.1. Web projects with F#

Exposing data over HTTP in .NET is most commonly done by using Microsoft’s ASP .NET framework; if you’ve done any form of web programming on .NET, it’s a safe bet that you’ve used it in some form, be it using the old-school Web Forms, its replacement MVC, or its API-focused sibling Web API. The most common and popular way to host an ASP .NET application in .NET is as a web project. These projects bootstrap into IIS (or its little sibling, IIS Express), with a web.config file providing configuration information to .NET (rather than an app.config).

37.2. Abstracting the Web API from F#

37.3. Working with Async

37.4. Introducing Suave

Summary