Last active
April 14, 2022 04:29
-
-
Save TheAngryByrd/8d65b1ab1ea4da60ac7ed8c1449f60ff to your computer and use it in GitHub Desktop.
F# MapGet helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open Microsoft.AspNetCore.Builder | |
open Microsoft.Extensions.Hosting | |
open Microsoft.AspNetCore.Http | |
open System.Threading.Tasks | |
let mapGet (pattern : string) handler (app : WebApplication) = | |
app.MapGet(pattern, (Func<_>(handler))) |> ignore | |
let mapGetAsync (pattern : string) (handler : HttpContext -> Task) (app : WebApplication) = | |
app.MapGet(pattern, RequestDelegate(handler)) |> ignore | |
let builder = WebApplication.CreateBuilder() | |
let app = builder.Build() | |
app |> mapGet "/" (fun () -> "hello world!") |> ignore | |
app |> mapGetAsync "/hello" (fun ctx -> task { do! ctx.Response.WriteAsync("hello", ctx.RequestAborted)}) |> ignore | |
app.Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment