Skip to main content

Module extractors

Module extractors 

Source
Expand description

Request body extractors.

JsonOrForm accepts a request body as EITHER application/json OR application/x-www-form-urlencoded (defaulting to JSON when the Content-Type is absent/unknown), so endpoints built with crate::http::BackboneCrudHandler — and any handler using it — work with both content types. Drop-in replacement for Json(x): Json<T> / Form(x): Form<T> in handler signatures and route closures.

A body that cannot be read as T is refused with the standard JSON error envelope (ApiResponse with success: false), never axum’s plain-text rejection: malformed JSON is a 400 with a malformed_body violation, and a well-formed body with a wrong or missing value is a 422 whose violation names the field (lines/3/amount).

StrictJsonOrForm additionally refuses a JSON body carrying a key T does not take (422, code unknown_field, the key as path): serde drops such a key silently, and the caller’s edit with it.

Structs§

JsonOrForm
Body extractor that accepts JSON or url-encoded form data. Keys the target type does not take are ignored; see StrictJsonOrForm for the variant that refuses them.
StrictJsonOrForm
JsonOrForm that refuses a JSON body carrying a key the target type does not take.