POST request with JSON body, unwrap `ApiResponse` envelope.
(
&self,
path: &str,
body: &B,
)
| 131 | |
| 132 | /// POST request with JSON body, unwrap `ApiResponse` envelope. |
| 133 | pub async fn post<B: Serialize, T: DeserializeOwned>( |
| 134 | &self, |
| 135 | path: &str, |
| 136 | body: &B, |
| 137 | ) -> Result<T, RemoteError> { |
| 138 | let url = format!("{}{}", self.base_url, path); |
| 139 | log::debug!("POST {}", url); |
| 140 | |
| 141 | let resp = self |
| 142 | .http |
| 143 | .post(&url) |
| 144 | .json(body) |
| 145 | .send() |
| 146 | .await |
| 147 | .map_err(|e| RemoteError::other(format!("request failed: {}", e)))?; |
| 148 | |
| 149 | self.handle_response(resp).await |
| 150 | } |
| 151 | |
| 152 | /// POST with no request body, unwrap `ApiResponse` envelope. |
| 153 | pub async fn post_empty<T: DeserializeOwned>(&self, path: &str) -> Result<T, RemoteError> { |
no test coverage detected