[−][src]Function reign_view::json
pub fn json<S: Serialize>(
value: S,
status: u16
) -> Result<Response<Body>, Error>
Serializes and sends JSON for reign_router handler.
The response is sent with content-type set as application/json
.
Examples
use reign::{ view::json, router::{HandleFuture, Request, futures::FutureExt}, }; #[derive(Serialize)] struct User<'a> { name: &'a str } fn handler(req: &mut Request) -> HandleFuture { async move { Ok(json(User { name: "Reign" }, 200)?) }.boxed() }