tobogganSe connecter

packages

The Louise packages, each released on its own

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

36 lignes · 869 octetsBrut · Historique
1/// Requests decoded with a `form` schema: a handler gets the decoded
2/// value, and a request the schema refuses is `Unreadable`.
3
4import form.{type Schema}
5import reply.{type Reply, Unreadable}
6import std/http.{type Request}
7
8/// `found` with `req`'s body decoded by `schema`.
9pub fn decoded ::
10 req: Request
11 schema: Schema<a>
12 found: fn(a) -> Reply / <e>
13 -> Reply / <e>
14{
15 read (http.form_body req) schema found
16}
17
18/// `found` with `req`'s query parameters decoded by `schema`.
19pub fn queried ::
20 req: Request
21 schema: Schema<a>
22 found: fn(a) -> Reply / <e>
23 -> Reply / <e>
24{
25 read (http.query_params req) schema found
26}
27
28fn read ::
29 values: List<(String, String)>
30 schema: Schema<a>
31 found: fn(a) -> Reply / <e>
32 -> Reply / <e>
33{
34 match form.new schema |> form.add_values values |> form.run
35 { Ok(value) -> found value, Error(_) -> Unreadable }
36}