POST request with JSON body, unwrap `ApiResponse` envelope.
(
&self,
path: &str,
body: &B,
)
| 163 | |
| 164 | /// POST request with JSON body, unwrap `ApiResponse` envelope. |
| 165 | pub async fn post<B: Serialize, T: DeserializeOwned>( |
| 166 | &self, |
| 167 | path: &str, |
| 168 | body: &B, |
| 169 | ) -> Result<T, RemoteError> { |
| 170 | let url = format!("{}{}", self.base_url, path); |
| 171 | log::debug!("POST {}", url); |
| 172 | |
| 173 | let resp = self |
| 174 | .http |
| 175 | .post(&url) |
| 176 | .json(body) |
| 177 | .send() |
| 178 | .await |
| 179 | .map_err(|e| RemoteError::other(format!("request failed: {}", e)))?; |
| 180 | |
| 181 | self.handle_response(resp).await |
| 182 | } |
| 183 | |
| 184 | /// POST with no request body, unwrap `ApiResponse` envelope. |
| 185 | pub async fn post_empty<T: DeserializeOwned>(&self, path: &str) -> Result<T, RemoteError> { |
no test coverage detected