Struct axum::response::Json [−][src]
pub struct Json<T>(pub T);
Expand description
A JSON response.
Can be created from any type that implements serde::Serialize
.
Will automatically get Content-Type: application/json
.
Example
use serde_json::json; use axum::{body::Body, response::{Json, IntoResponse}}; use http::{Response, header::CONTENT_TYPE}; let json = json!({ "data": 42, }); let response: Response<Body> = Json(json).into_response(); assert_eq!( response.headers().get(CONTENT_TYPE).unwrap(), "application/json", );
Tuple Fields
0: T
Trait Implementations
Create a response.
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