Struct axum::extract::Json [−][src]
pub struct Json<T>(pub T);
Expand description
Extractor that deserializes request bodies into some type.
T
is expected to implement serde::Deserialize
.
Example
use axum::prelude::*; use serde::Deserialize; #[derive(Deserialize)] struct CreateUser { email: String, password: String, } async fn create_user(payload: extract::Json<CreateUser>) { let payload: CreateUser = payload.0; // ... } let app = route("/users", post(create_user));
If the query string cannot be parsed it will reject the request with a 400 Bad Request
response.
The request is required to have a Content-Type: application/json
header.
Tuple Fields
0: T
Trait Implementations
type Rejection = JsonRejection
type Rejection = JsonRejection
If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response. Read more
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Perform the extraction.
Auto Trait Implementations
impl<T> RefUnwindSafe for Json<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Json<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Create a new Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more
type Output = T
type Output = T
Should always be Self