use http::Request; use http_body_util::BodyExt; use hyper::body::Incoming; use serde::de::DeserializeOwned; use std::{any::TypeId, error::Error}; pub struct Requester; impl Requester { pub async fn extract_body(req: Request) -> Result> where T: DeserializeOwned + 'static, { let body = req.collect().await?.to_bytes(); if TypeId::of::() == TypeId::of::() { let string = String::from_utf8(body.to_vec())?; return Ok(serde_json::from_str(&string)?); } Ok(serde_json::from_slice(&body)?) } }