This document discusses the SAFE stack, an alternative approach to .NET web development using F# and functional programming principles. The SAFE stack includes the Suave web server, Azure cloud platform, Fable compiler to compile F# to JavaScript, and Elmish single-page app architecture. It provides advantages like less verbose code, better developer experience with tools like Paket and Fake, and the ability to share code between server and client. Various sample applications and deployment options for the SAFE stack are presented.
17. Киев 2017
WebParts: Filters
Path "/foo"
// returns None if path does not
// match
GET
// returns None if verb does not
// match
@skalinets 17
18. Киев 2017
WebParts: Combinators
a >=> b
// returns None if a is None
// otherwise feeds result of a
// into b and returns its result
@skalinets 18
19. Киев 2017
WebParts: Combinators
choose [a; b]
// returns None if a is None
// otherwise feeds result of a
// into b and returns its result
@skalinets 19
20. Киев 2017
Config Example
choose
[ GET >=> path "/public" >=> OK "Default GET"
// Access to handlers after this one will require
authentication
Authentication.authenticateBasic
(fun (user,pwd) -> user = "foo" && pwd = "bar")
(choose [
GET>=> path "/whereami"
>=> OK "Hello authenticated person"
GET >=> path "/" >=> dirHome
GET >=> browseHome // Serves file if exists
])]
@skalinets 20
28. Киев 2017
Elmish: The Basics
type Model = int
type Msg =
| Increment
| Decrement
| Reset
@skalinets 28
29. Киев 2017
Elmish: The Basics
let init () : Model = 0
let update msg model =
match msg with
| Increment -> model + 1
| Decrement -> model - 1
| Reset -> 0
@skalinets 29
33. Киев 2017
IDE: Visual Studio Code
Nice lightweight IDE
Many various extensions
Ionide – extension for F#
@skalinets 33
34. Киев 2017
Acceptance Tests: canopy
F# wrapper around WebDriver
Very nice syntax
Can be understood
by
non-developers
@skalinets 34
35. Киев 2017
Testcase
Open url http://site.com
Enter “Minnie” as First Name
Select Female Gender
Click “Continue”
Verify that First Name is “Minnie”
@skalinets 35
43. Киев 2017
SAFE is not all-or-nothing
You can use alternative
application architectures
utilizing elements of SAFE
stack in different ways
@skalinets 43