2025-01-18 21:27:14 +01:00
|
|
|
use http::Request;
|
|
|
|
use http_body_util::BodyExt;
|
|
|
|
use hyper::body::Incoming;
|
|
|
|
use serde::de::DeserializeOwned;
|
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
pub struct Requester;
|
|
|
|
|
|
|
|
impl Requester {
|
2025-01-18 21:35:15 +01:00
|
|
|
pub async fn extract_body<T>(req: Request<Incoming>) -> Result<T, Box<dyn Error + Send + Sync>>
|
2025-01-18 21:27:14 +01:00
|
|
|
where
|
|
|
|
T: DeserializeOwned,
|
|
|
|
{
|
|
|
|
let body = req.collect().await.unwrap().to_bytes();
|
|
|
|
Ok(serde_json::from_slice(&body)?)
|
|
|
|
}
|
|
|
|
}
|