Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active June 9, 2020 15:09
Show Gist options
  • Select an option

  • Save isaacabraham/a828ad2a4691fb1467769c8a6bc8517f to your computer and use it in GitHub Desktop.

Select an option

Save isaacabraham/a828ad2a4691fb1467769c8a6bc8517f to your computer and use it in GitHub Desktop.
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
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