wx_rust_common/util/http/
simple_post_request_executor.rs1use async_trait::async_trait;
7
8use crate::enums::WxType;
9use crate::error::WxErrorException;
10use crate::util::http::simple_get_request_executor::SimpleGetRequestExecutor;
11use crate::util::http::{RequestExecutor, ResponseHandler};
12
13#[derive(Debug, Clone)]
17pub struct SimplePostRequestExecutor {
18 client: reqwest::Client,
20}
21
22impl SimplePostRequestExecutor {
23 pub fn new(client: reqwest::Client) -> Self {
28 Self { client }
29 }
30}
31
32#[async_trait]
33impl RequestExecutor<String, String> for SimplePostRequestExecutor {
34 async fn execute(
35 &self,
36 uri: &str,
37 data: String,
38 wx_type: WxType,
39 ) -> Result<String, WxErrorException> {
40 let resp = self.client.post(uri).body(data).send().await?;
41 let body = resp.text().await?;
42 SimpleGetRequestExecutor::handle_response(wx_type, &body)
43 }
44}
45
46#[async_trait]
47impl ResponseHandler<String> for SimplePostRequestExecutor {
48 async fn handle(&self, response: String) {
49 let _ = response;
50 }
51}