[−][src]Function hyperbole::body::auto
pub async fn auto<T>(
cx: HCons<Body, HCons<HeaderMap, HNil>>
) -> Result<HCons<T, HCons<HeaderMap, HNil>>, AutoBodyError> where
T: DeserializeOwned,
Deserialize a value from the request body, using the Content-Type
header to determine the
serialization format.
Use with Ctx::handle_with
or Ctx::try_then
.
Examples
use hyperbole::{body::auto, record_args, uri, Ctx}; use serde::Deserialize; #[derive(Deserialize)] struct ThingRequest { x: u32, y: String, } #[record_args] async fn the_thing(_: ThingRequest) -> &'static str { "yepperz" } let _ctx = Ctx::default() // inline with get_with: .get_with(uri!["the-thing"], auto::<ThingRequest>, the_thing) // or as a middleware: .try_then(auto::<ThingRequest>) .get(uri!["the-thing" / "via-mw"], the_thing);