pub trait FromRequest: Sized + Send {
type Error: IntoResponse;
// Required method
fn from_request(
parts: &Parts,
body: Bytes,
) -> impl Future<Output = Result<Self, Self::Error>> + Send;
}Expand description
Extract a value by consuming the request body.
At most one FromRequest extractor can appear per handler (as the last
argument), since it consumes the body.
Required Associated Types§
Sourcetype Error: IntoResponse
type Error: IntoResponse
The error type returned when extraction fails.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl FromRequest for ()
Unit extractor — always succeeds, ignoring the body.
impl FromRequest for ()
Unit extractor — always succeeds, ignoring the body.
Source§impl FromRequest for String
impl FromRequest for String
Source§impl FromRequest for Bytes
impl FromRequest for Bytes
Implementors§
Source§impl<T: DeserializeOwned + Send> FromRequest for Json<T>
JSON request body extractor.
impl<T: DeserializeOwned + Send> FromRequest for Json<T>
JSON request body extractor.
Parses the request body as JSON. Requires Content-Type: application/json.
§Example
ⓘ
async fn create_user(Json(body): Json<CreateUser>) -> Json<User> {
// body: CreateUser, deserialized from JSON
}