grammarbot_io/
client.rs

1use crate::{HttpRequest, Request};
2
3impl Request {
4    /// Sends the request and returns the response using default client.
5    pub fn send(&self) -> Result<crate::response::Response, reqwest::Error> {
6        HttpRequest::from(self).send()
7    }
8
9    /// Sends the request using the provided client.
10    pub fn send_with_client(
11        &self,
12        client: &reqwest::blocking::Client,
13    ) -> Result<crate::response::Response, reqwest::Error> {
14        HttpRequest::from(self).send_with_client(client)
15    }
16}
17
18impl HttpRequest {
19    /// Sends the request and returns the response using default client.
20    pub fn send(&self) -> Result<crate::response::Response, reqwest::Error> {
21        self.send_with_client(&reqwest::blocking::Client::new())
22    }
23
24    /// Sends the request using the provided client.
25    pub fn send_with_client(
26        &self,
27        client: &reqwest::blocking::Client,
28    ) -> Result<crate::response::Response, reqwest::Error> {
29        let mut request = client.post(&self.url);
30        for (k, v) in &self.headers {
31            request = request.header(k, v);
32        }
33        request.form(&self.data).send()?.json()
34    }
35}