Create an HTTP client. # Arguments `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com"
(base_path: &str)
| 202 | /// # Arguments |
| 203 | /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" |
| 204 | pub fn try_new(base_path: &str) -> Result<Self, ClientInitError> { |
| 205 | let uri = Uri::from_str(base_path)?; |
| 206 | |
| 207 | let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?; |
| 208 | let scheme = scheme.to_ascii_lowercase(); |
| 209 | |
| 210 | let connector = Connector::builder(); |
| 211 | |
| 212 | let client_service = match scheme.as_str() { |
| 213 | "http" => HyperClient::Http(hyper::client::Client::builder().build(connector.build())), |
| 214 | "https" => { |
| 215 | let connector = connector |
| 216 | .https() |
| 217 | .build() |
| 218 | .map_err(ClientInitError::SslError)?; |
| 219 | HyperClient::Https(hyper::client::Client::builder().build(connector)) |
| 220 | } |
| 221 | _ => { |
| 222 | return Err(ClientInitError::InvalidScheme); |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | let client_service = DropContextService::new(client_service); |
| 227 | |
| 228 | Ok(Self { |
| 229 | client_service, |
| 230 | base_path: into_base_path(base_path, None)?, |
| 231 | marker: PhantomData, |
| 232 | }) |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | impl<C> Client<DropContextService<hyper::client::Client<hyper::client::HttpConnector, Body>, C>, C> |
nothing calls this directly
no test coverage detected