Skip to main content

Module input

Module input 

Source
Expand description

Turning query strings and form bodies into a uniform JSON tree.

Everything downstream of the request — input(), validation rules, Form<T> deserialisation — reads one shape: a serde_json::Value. A JSON body already is one; a query string or a urlencoded form has to be lifted into one, and that lift is where PHP-style bracket notation is honoured:

QueryValue
a=1&b=2{"a": "1", "b": "2"}
tags[]=x&tags[]=y{"tags": ["x", "y"]}
user[name]=ada{"user": {"name": "ada"}}
a=1&a=2{"a": ["1", "2"]}

Values stay strings. A form has no types — ?active=1 could be the number one or the string “1” — so guessing here would make Form<T>/validation behaviour depend on what the value happened to look like. Coercion is the validator’s job, where the expected type is known.

Functions§

lookup
Read a dotted path out of a JSON tree. items.0.name indexes arrays.
merge
Merge overlay over base, recursing into objects.
parse_urlencoded
Parse application/x-www-form-urlencoded bytes (a query string or a form body) into a JSON object.
scalar_to_string
Render a JSON value as the string an input() caller expects.