[][src]Function hyperbole::body::autor

pub async fn autor<T>(
    cx: HCons<Body, HCons<HeaderMap, HNil>>
) -> Result<HCons<HeaderMap, T>, AutoBodyError> where
    T: HList + IsoDecode

Deserialize an anonymous record from the request body, using the Content-Type header to determine the serialization format.

This can be used to specify a request body without declaring a bespoke request struct, while maintaining type safe access to the payload.

Any fields of the record will be merged into the context's state as if they were provided inline.

Use with Ctx::handle_with or Ctx::try_then.

Examples

use hyperbole::{body::autor, record_args, uri, Ctx, R};

#[record_args]
async fn the_thing(x: u32, y: String, z: f64) -> &'static str {
    "yepperz"
}

let _ctx = Ctx::default()
    // inline with get_with:
    .get_with(uri!["the-thing"], autor::<R![x: _, y: _, z: _]>, the_thing)
    // or as a middleware:
    .try_then(autor::<R![x: _, y: _]>)
    .get(uri!["the-thing" / z: f64], the_thing);