Perform a POST request with a JSON body. # Arguments `path` - The path to append to the base URL. `body` - The JSON body to send. # Returns The parsed JSON response.
(
&self,
path: &str,
body: &B,
)
| 136 | /// # Returns |
| 137 | /// The parsed JSON response. |
| 138 | pub async fn post<T: DeserializeOwned, B: serde::Serialize>( |
| 139 | &self, |
| 140 | path: &str, |
| 141 | body: &B, |
| 142 | ) -> Result<T> { |
| 143 | let url = self.request_url(path); |
| 144 | let body_str = serde_json::to_string(body).ok(); |
| 145 | let headers = self |
| 146 | .build_auth_headers("POST", path, body_str.as_deref(), HashMap::new()) |
| 147 | .await?; |
| 148 | let request = self.client.post(&url).json(body); |
| 149 | let request = Self::apply_headers(request, &headers); |
| 150 | let resp = request.send().await.map_err(|e| Error::UnexpectedError { |
| 151 | message: "http post failed".to_string(), |
| 152 | source: Some(Box::new(e)), |
| 153 | })?; |
| 154 | self.parse_response(resp).await |
| 155 | } |
| 156 | |
| 157 | /// Perform a DELETE request with optional query parameters. |
| 158 | /// |