Build an ASP.NET Core Web App with F#? You must be having a Giraffe!
https://stu.dev
Slide 2
Hello!
https://stu.dev https://stu.dev
2
Slide 3
What I’ll cover
◉ ◉ ◉ ◉ ◉
https://stu.dev
What is Giraffe? Where does it fit in? Why F#? How does Giraffe work? Questions
3
Slide 4
1
https://stu.dev
What is it?
4
Slide 5
5
A functional ASP.NET Core micro web framework for building rich web applications.
“ https://stu.dev
Slide 6
Idiomatic C#
https://stu.dev
Idiomatic F#
6
Slide 7
(Saturn)
https://stu.dev
7
Slide 8
ThoughtWorks Technology Radar
https://stu.dev
8
Slide 9
1
https://stu.dev
Why F#?
9
Slide 10
Why F#?
Like C# it’s ◉ General Purpose, so can be used for ○ ○ ○ ○ ○ ○ https://stu.dev
Web apps Microservices Cloud apps Xamarin apps Desktop … 10
Slide 11
Why F#?
Like C# it’s ◉ Multi-paradigm ○ Functional first ○ Imperative and mutability when you need it ○ OO when you need it
https://stu.dev
11
Slide 12
Why F#?
Like C# it’s ◉ Out-of-the-box with .NET Core SDK ○ It’s there, and project templates
https://stu.dev
12
Slide 13
Why F#?
Like C# it’s ◉ Got great tooling support
https://stu.dev
13
Slide 14
Why F#?
You don’t need to ask your boss Stu says it’s fine!
https://stu.dev
14
Slide 15
Why F#?
F# is concise and low ceremony
https://stu.dev
15
Slide 16
Why F#?
Correctness ◉ Solves the null problem ◉ Immutable by default ◉ Make invalidate state impossible to represent
https://stu.dev
16
Slide 17
Why F#? - Forward Pipe
Functions and values can have any name you chose https://stu.dev
17
Slide 18
Why F#? - Records
https://stu.dev
18
Slide 19
Why F#? - Discriminated Unions
Credit: Luke Merrett https://stu.dev
19
Slide 20
Why F#?
It’s great for domain modelling
20
Slide 21
1
https://stu.dev
How does it work?
21
Slide 22
An example Giraffe app (source) https://stu.dev
22
Slide 23
Let’s model it!
type HttpServer =
https://stu.dev
23
Slide 24
Let’s model it!
type HttpHandler =
https://stu.dev
24
Slide 25
Let’s model it!
https://stu.dev
25
Slide 26
Let’s model it!
Taking inspiration from Suave… https://stu.dev
26
Slide 27
Let’s model it!
type HttpHandler =
https://stu.dev
27
Slide 28
Let’s model it!
https://stu.dev
28
Slide 29
Let’s model it!
type HttpHandler =
https://stu.dev
29
Slide 30
Let’s model it!
(compose / >=>)
https://stu.dev
30
Slide 31
Let’s model it!
https://stu.dev
31
Slide 32
Let’s model it!
https://stu.dev
32
Slide 33
Let’s model it!
https://stu.dev
33
Slide 34
Let’s model it!
https://stu.dev
34
Slide 35
Let’s model it!
(btw, this is just the same as:)
https://stu.dev
35
Slide 36
Let’s model it!
type HttpHandler =
https://stu.dev
36
Slide 37
Let’s model it!
https://stu.dev
37
Slide 38
Let’s model it!
https://stu.dev
38
Slide 39
Let’s model it!
But it could be better… https://medium.com/@gerardtoconnor/carry-on-continuation -over-binding-pipelines-for-functional-web-58bd7e6ea009
https://stu.dev
39
Slide 40
Let’s model it!
type HttpFunc =
type HttpHandler =
https://stu.dev
40
Slide 41
Let’s model it!
https://stu.dev
41
Slide 42
Let’s model it!
type HttpFunc =
type HttpHandler =
https://stu.dev
42
Slide 43
Let’s model it!
Familiar… ASP.NET Core Middleware
https://stu.dev
43