Operators
Suave keeps a small set of operators. Prefer readability over cryptic symbol soup.
| Operator | Meaning |
|---|---|
>=> | Left-to-right Kleisli composition of WebParts (run left, then right if Some). |
<|> | Try left; if it fails (None), try right. Useful as a binary alternative to short choose lists. |
? | Look up a key in a dictionary-like structure (open Suave.Utils.Collections). |
%% | Search a list of key/value pairs; return the value or None. |
^^ | Search a list of key/optional-value pairs; return the value or None. |
?<- | Assign a value for a key in a dictionary. |
Example
open Suave
open Suave.Filters
open Suave.Operators
open Suave.Successful
open Suave.Utils.Collections
let greetings q =
defaultArg (Suave.Utils.Option.ofChoice (q ^^ "name")) "World"
|> sprintf "Hello %s"
let app =
path "/hello" >=> choose [
GET >=> request (fun r -> OK (greetings r.query))
POST >=> request (fun r -> OK (greetings r.form))
]Full signatures: API reference.