13 Web Programming
This chapter covers
- The Web and Functional Programming
- Web Programming on .NET and F#
- Server-side web development in F#
- Client-side development with Elmish
- The SAFE Stack
This chapter is one that’ll tie together even more of what we’ve seen so far, bringing both the functional paradigm as well as core abstractions such as Task-based asynchronous programming and Options to enable web programming that naturally fits with F#.
13.1 The Web and Functional Programming
This section gives a brief re-cap on HTTP and explains why (although this may surprise you) FP is a natural fit for web programming.
One of the fundamental underpinnings of the web today was the invention of the Hypertext Transfer Protocol (HTTP), which provided a standard messaging format for web traffic. These days we see lots of frameworks use OOP patterns as a way of modelling web applications such as Controllers. In such frameworks, you often create classes which have methods that are decorated in some way such that web requests are correctly “routed” to a method; you’ll often have to inherit from “base classes” which give extra functionality. All of this is especially unfortunate because it's just hiding what HTTP really is:
Figure 13.1 An HTTP closely matches a function call – a request payload followed by a response from the server.
