pub struct Json<T>(pub T);Expand description
JSON body extractor.
Extracts a JSON body from the request and deserializes it to type T.
§Error Responses
- 415 Unsupported Media Type: Content-Type is not
application/json - 413 Payload Too Large: Body exceeds configured size limit
- 422 Unprocessable Entity: JSON parsing failed
§Example
ⓘ
use fastapi_core::extract::Json;
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateUser {
name: String,
email: String,
}
async fn create_user(Json(user): Json<CreateUser>) -> impl IntoResponse {
format!("Created user: {}", user.name)
}Tuple Fields§
§0: TImplementations§
Source§impl<T> Json<T>
impl<T> Json<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap the inner value.
Trait Implementations§
Source§impl<T: DeserializeOwned> FromRequest for Json<T>
impl<T: DeserializeOwned> FromRequest for Json<T>
Source§type Error = JsonExtractError
type Error = JsonExtractError
Error type when extraction fails.
Source§async fn from_request(
ctx: &RequestContext,
req: &mut Request,
) -> Result<Self, Self::Error>
async fn from_request( ctx: &RequestContext, req: &mut Request, ) -> Result<Self, Self::Error>
Extract a value from the request. Read more
Source§impl<T: Serialize> IntoResponse for Json<T>
impl<T: Serialize> IntoResponse for Json<T>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert into a response.
impl<T: Copy> Copy for Json<T>
impl<T: Serialize + 'static> ResponseProduces<T> for Json<T>
Auto Trait Implementations§
impl<T> Freeze for Json<T>where
T: Freeze,
impl<T> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T> Send for Json<T>where
T: Send,
impl<T> Sync for Json<T>where
T: Sync,
impl<T> Unpin for Json<T>where
T: Unpin,
impl<T> UnwindSafe for Json<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).