我想用Suave建立一个简单的计数器。
[<EntryPoint>] let main argv = let mutable counter = 0; let app = choose [ GET >=> choose [ path "/" >=> OK "Hello, world. "; path "/count" >=> OK (string counter) ] POST >=> choose [ path "/increment" >=> (fun context -> async { counter <- counter + 1 return Some context }) ] ] startWebServer defaultConfig app 0
/count 从不更新。
/count
我想这是因为 WebPart
WebPart
你的假设是对的 Webpart s是值,因此计算一次。(见 this ).
Webpart
path "/count" >=> (fun ctx -> async { let c = counter in return! OK (string c) ctx })