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.
Dernier runRéussi#28 · main · 3 min 34 s
0Étoiles
0Forks
3Issues
| 1 | /// Requests decoded with a `form` schema: a handler gets the decoded |
| 2 | /// value, and a request the schema refuses is `Unreadable`. |
| 3 | |
| 4 | import form.{type Schema} |
| 5 | import reply.{type Reply, Unreadable} |
| 6 | import std/http.{type Request} |
| 7 | |
| 8 | /// `found` with `req`'s body decoded by `schema`. |
| 9 | pub 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`. |
| 19 | pub 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 | |
| 28 | fn 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 | } |