pub struct Json<T>(pub T);Available on crate features
http and json only.Expand description
A JSON wrapper for request and response bodies.
Wraps a value of type T and serializes it as JSON when used as a response,
automatically setting the Content-Type: application/json header.
§Examples
ⓘ
use spin_sdk::http::{Json, Request};
use spin_sdk::http_service;
use serde::Serialize;
#[derive(Serialize)]
struct User { name: String }
#[http_service]
async fn handler(_req: Request) -> impl IntoResponse {
Json(User { name: "Alice".into() })
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Serialize> IntoResponse for Json<T>
impl<T: Serialize> IntoResponse for Json<T>
Source§fn into_response(self) -> Result<Response, ErrorCode>
fn into_response(self) -> Result<Response, ErrorCode>
Converts
self into a wasip3::http::types::Response.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> UnsafeUnpin for Json<T>where
T: UnsafeUnpin,
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