I have a simple Suave.io server in the form:
let Ok o = o |> JsonConvert.SerializeObject |> Successful.OK
let NotOk o = o |> JsonConvert.SerializeObject |> RequestErrors.BAD_REQUEST
type Result<'T> =
| Success of 'T
| Failure of string
let DoThing someParam anotherParam =
let stats = Success(999) // <- business code here
match stats with
| Success s -> s |> Ok
| Failure m -> m |> NotOk
...
let app =
choose
[ GET >=> choose
[
pathScan "/someroute/%i/%i" (fun (p1, p2) ->
DoThing p1 p2)
]
]
startWebServer config app
0
I would like to check that the request contains a header with a certain name and value and return NotOk when it is absent or incorrect. What's the simplest way to achieve this?
I'm a newcomer to Suave.io's compositional style.
type WebPart = HttpContext -> Async<HttpContext option>
andtype HttpContext = { request: HttpRequest; response: HttpResponse }
. So you need to unwrap theWebPart
. – Shaduf