[][src]Function hyperbole::body::jsonr

pub async fn jsonr<T: IsoDecode>(
    cx: HCons<Body, HNil>
) -> Result<T, JsonBodyError>

Deserialize an anonymous record from a json request body.

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::jsonr, 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"], jsonr::<R![x: _, y: _, z: _]>, the_thing)
    // or as a middleware:
    .try_then(jsonr::<R![x: _, y: _]>)
    .get(uri!["the-thing" / z: f64], the_thing);