diff --git a/src/lib.rs b/src/lib.rs index 7168272..133fb5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,9 @@ mod builder; mod config; +mod requester; mod responder; mod server; +pub use requester::Requester; pub use responder::Responder; pub use server::Server; diff --git a/src/requester.rs b/src/requester.rs new file mode 100644 index 0000000..7f972e1 --- /dev/null +++ b/src/requester.rs @@ -0,0 +1,17 @@ +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 { + pub async fn extract_body(req: Request) -> Result> + where + T: DeserializeOwned, + { + let body = req.collect().await.unwrap().to_bytes(); + Ok(serde_json::from_slice(&body)?) + } +}