/// Requests decoded with a `form` schema: a handler gets the decoded /// value, and a request the schema refuses is `Unreadable`. import form.{type Schema} import reply.{type Reply, Unreadable} import std/http.{type Request} /// `found` with `req`'s body decoded by `schema`. pub fn decoded :: req: Request schema: Schema found: fn(a) -> Reply / -> Reply / { read (http.form_body req) schema found } /// `found` with `req`'s query parameters decoded by `schema`. pub fn queried :: req: Request schema: Schema found: fn(a) -> Reply / -> Reply / { read (http.query_params req) schema found } fn read :: values: List<(String, String)> schema: Schema found: fn(a) -> Reply / -> Reply / { match form.new schema |> form.add_values values |> form.run { Ok(value) -> found value, Error(_) -> Unreadable } }