Last active
June 9, 2020 15:09
-
-
Save isaacabraham/a828ad2a4691fb1467769c8a6bc8517f to your computer and use it in GitHub Desktop.
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 Giraffe | |
| open Saturn | |
| let myRouter = choose [ | |
| route "/api/public" >=> text "Hello" | |
| requiresAuthentication (RequestErrors.UNAUTHORIZED "" "" "admin check") >=> route "/api/admin" >=> text "ADMIN" | |
| requiresAuthentication (RequestErrors.UNAUTHORIZED "" "" "customer check") >=> route "/api/customer" >=> text "CUSTOMER" | |
| ] | |
| let a = application { | |
| use_router myRouter | |
| } | |
| run a |
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 Giraffe | |
| open Microsoft.AspNetCore.Hosting | |
| open Microsoft.AspNetCore.Builder | |
| open Microsoft.Extensions.Hosting | |
| let app = choose [ | |
| route "/api/public" >=> text "Hello" | |
| requiresRole "admin" (RequestErrors.UNAUTHORIZED "" "" "admin check") >=> route "/api/admin" >=> text "ADMIN" | |
| requiresRole "customer" (RequestErrors.UNAUTHORIZED "" "" "customer check") >=> route "/api/customer" >=> text "CUSTOMER" | |
| ] | |
| Host.CreateDefaultBuilder() | |
| .ConfigureWebHostDefaults(fun webBuilder -> | |
| webBuilder | |
| .Configure(fun appBuilder -> appBuilder.UseGiraffe app) | |
| .ConfigureServices(fun services -> services.AddGiraffe() |> ignore) | |
| |> ignore | |
| ) | |
| .Build() | |
| .Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment