Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A variant of pathScan that also passes HttpContext to the handler
#r "<path/to/Suave.dll>"
open Suave
open Suave.Successful
open Suave.RequestErrors
/// <summary>
/// Same as pathScan but also passes the HttpContext to the handler h.
/// See pathScan:
/// </summary>
let pathScanContext (pf : PrintfFormat<_,_,_,_,'t>) (h : HttpContext -> 't -> WebPart) : WebPart =
let scan url =
let r = Sscanf.sscanf pf url
Some r
with _ -> None
let F (r: HttpContext) =
match scan r.request.path with
| Some p ->
let part = h r p
part r
| None ->
// This lets us write the example ( ) in a simpler form:
let handler ctx (a, b) =
// get something from ctx.request...
OK((a + b).ToString())
let testapp : WebPart =
[ pathScanContext "/add/%d/%d" handler
NOT_FOUND "Found no handlers" ]
startWebServer defaultConfig testapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.