Skip to main content

Module binding

Module binding 

Source
Expand description

Request model binding — the runtime half of #[derive(WebxRequestMeta)].

A request struct declares where each field comes from (#[frompath], #[fromquery], #[frombody], #[fromform], #[fromheader], #[fromclaim]). The derive compiles that declaration into a RequestModel::bind implementation; this module provides the value providers and coercion helpers that implementation calls.

§Why not serde for query/path/header/claim

HTTP values are strings, often repeated (?id=1&id=2), and a failure in one field must not hide the others. serde_json models documents, not HTTP values, so it cannot coerce "2" into u32, cannot represent repeated keys, and fails at the first error. Here every scalar is parsed with FromStr, lists keep every occurrence, and failures accumulate in a Binder so the response can report all of them at once.

JSON bodies stay with serde: the derive generates a hidden body struct containing only the body-bound fields, so rename, flatten, default and custom deserializers keep working exactly as written.

Structs§

BindInput
The value providers a generated RequestModel::bind reads from.
Binder
Accumulates field-level binding failures into one 400 response.

Enums§

Source
Where a request field’s value comes from.

Traits§

RequestModel
A type that can be constructed from an HTTP request.

Functions§

body_error
Convert a JSON body deserialization failure into a field-level 400.
body_field_error
A field-level body failure: the JSON key was present but its value did not match the field type.
is_body_method
Whether method carries a JSON body by default (ASP.NET Core’s rule).
split_csv
Expand one optional raw value into a list, splitting on commas.
take_body_field
Remove key (or one of aliases) from a JSON object.