-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelloWorld.fs
More file actions
33 lines (28 loc) · 884 Bytes
/
HelloWorld.fs
File metadata and controls
33 lines (28 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
open Falco
open Falco.Markup
open Falco.Routing
open Falco.Datastar
open Microsoft.AspNetCore.Builder
let handleIndex : HttpHandler =
let html =
Elem.html [] [
Elem.head [] [ Ds.cdnScript ]
Elem.body [] [
Text.h1 "Example: Hello World"
Elem.button
[ Attr.id "hello"; Ds.onClick (Ds.get "/click") ]
[ Text.raw "Click Me" ]
]
]
Response.ofHtml html
let handleClick : HttpHandler =
// create an HTML element which will replace the button with the same `id`
let html = Elem.h2 [ Attr.id "hello" ] [ Text.raw "Hello, World, from the Server!" ]
Response.ofHtmlElements html
let wapp = WebApplication.Create()
let endpoints =
[ get "/" handleIndex
get "/click" handleClick ]
wapp.UseRouting()
.UseFalco(endpoints)
.Run()