我正在尝试用Suave.io写一个网站,并有一个表格可以作为帖子提交或获取请求。我找到了一个如何将表单值绑定到dto的示例,但是找不到如何将查询参数绑定到同一个dto的方法。
let app : WebPart =
choose
[ path "/api" >>= GET >>= Binding.bindReq (bindQuery params_form) classify BAD_REQUEST
path "/api/v2/" >>= POST >>= Binding.bindReq (bindForm params_form) classify BAD_REQUEST
NOT_FOUND "Found no handlers" ]
startWebServer defaultConfig app
答案 0 :(得分:2)
从版本0.32开始,没有任何内容。你必须自己做:
let withMyDTo fSuccess FFailure =
request ( fun r ->
let myValue1 = r.queryParam "val1"
let myValue2 = r.queryParam "val2"
match myValue1,myValue2 with
| Choice1Of2(v1),Choice1Of2(v2) -> fSuccess { val1:v1; val2:v2 }
| _,_ -> FFailure
)
choose [path "ddd" >>= withMyDTo doThat OhDoThatThen]