-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.fs
46 lines (37 loc) · 1.28 KB
/
Program.fs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
// Kind of like a controller, gluing routes to models.
open Falco
open Falco.Routing
open Falco.HostBuilder
let livenessHandler = Response.ofJson {| Ok = "Ok" |}
let dayHandler =
Request.mapRoute
// How to extract route variables from the route
(fun r -> r.GetInt "day" 0)
// The route handler receives the extracted route variable
(fun dayNumber ->
Response.ofJson
{| day = dayNumber
today = Schedule.getDay(dayNumber).Default
alternative = Schedule.getDay(dayNumber).Alternative |})
let configHandler = Config.load () |> Response.ofJson
let scheduleHandler =
Response.ofJson {| schedule = Schedule.buildYearly().Default |}
let todayHandler =
let dayNumber = System.DateTime.Today.DayOfYear
Response.ofJson
{| day = dayNumber
today = Schedule.getDay(dayNumber).Default
alternative = Schedule.getDay(dayNumber).Alternative |}
// Assembles all request handlers into one webserver
// Configures routes to handlers
[<EntryPoint>]
let main _argv =
webHost [||] {
endpoints
[ get "/liveness" livenessHandler
get "/config" configHandler
get "/schedule" scheduleHandler
get "/today" todayHandler
get "/day/{day:int}" dayHandler ]
}
0