POST request with JSON body, unwrap `ApiResponse` envelope.
(
&self,
path: &str,
body: &B,
)
| 106 | |
| 107 | /// POST request with JSON body, unwrap `ApiResponse` envelope. |
| 108 | pub async fn post<B: Serialize, T: DeserializeOwned>( |
| 109 | &self, |
| 110 | path: &str, |
| 111 | body: &B, |
| 112 | ) -> Result<T, RemoteError> { |
| 113 | let url = format!("{}{}", self.base_url, path); |
| 114 | log::debug!("POST {}", url); |
| 115 | |
| 116 | let resp = self |
| 117 | .http |
| 118 | .post(&url) |
| 119 | .json(body) |
| 120 | .send() |
| 121 | .await |
| 122 | .map_err(|e| RemoteError::other(format!("request failed: {}", e)))?; |
| 123 | |
| 124 | self.handle_response(resp).await |
| 125 | } |
| 126 | |
| 127 | /// POST with no request body, unwrap `ApiResponse` envelope. |
| 128 | pub async fn post_empty<T: DeserializeOwned>(&self, path: &str) -> Result<T, RemoteError> { |
no test coverage detected