End-to-end functional web development€¦ · Functional web development Request to response function F# but also Elixir, Clojure and more.. Web dev with Suave and F# ...

Post on 24-Jun-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

End-to-end functional web development

Tomas Petricek, fsharpWorks | | @tomaspetricek tomasp.net fsharpworks.com

The web is functional!

Request ‐> Response 

The web is asynchronous!

Request ‐> Async<Response> 

DEMOHello world and type providers

Demo summary

Lightweight and asynchronous

Great with type providers

Build and package infrastructure

Package management with PaketSpecify dependencies in paket.dependencies

1: 2: source https://nuget.org/api/v2 nuget Suave

Locked version numbers in paket.lock

1: 2: 3: 4: 5: 6: 7: 8:

NUGET remote: https://nuget.org/api/v2 specs: FSharp.Core (3.1.2.1) FsPickler (1.2.1) Suave (0.28.1) FSharp.Core (>= 3.1.2.1) FsPickler (>= 1.0.7)

Building and live reloading scriptFAKE for building and F# Compiler Service for reloading

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:

let reloadAppServer () = currentApp.Value <- reloadScript()

Target "run" (fun _ -> let app ctx = currentApp.Value ctx let _, server = startWebServerAsync serverConfig app Async.Start(server)

use watcher = !! (__SOURCE_DIRECTORY__ @@ "*.*") |> WatchChanges (fun _ -> reloadAppServer()) Console.ReadLine() )

DEMOBuilding chat app with agents

Demo summary

Composable library for REST APIs

Works with agent-based architecture

Scale with Akka.net, Cricket and M-Brace

Routing and handling headersUsing F# power for domain-specific languages

1: 2: 3: 4: 5:

choose [ path "/" >>= setMimeType "text/html" >>= index path "/chat" >>= GET >>= noCache >>= getMessages path "/post" >>= POST >>= noCache >>= postMessage NOT_FOUND "Found no handlers" ]

DEMODeploying chat app to Azure and Heroku

DEMOTesting chat app with FsCheck

Demo summary

Nice unit testing with simple syntax

Powerful random testing with FsCheck

Integrated with FAKE and CI servers

Summary

Functional web development

Request to response function

F# but also Elixir, Clojure and more..

Web dev with Suave and F#

www.fsharp.org

www.fsharpconf.com

www.suave.io

See for books & trainings! | |

functional-programming.net@tomaspetricek tomasp.net fsharpworks.com

top related