MCPcopy Create free account
hub / github.com/ceramicnetwork/rust-ceramic / try_new

Method try_new

api-server/src/client/mod.rs:204–233  ·  view source on GitHub ↗

Create an HTTP client. # Arguments `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com"

(base_path: &str)

Source from the content-addressed store, hash-verified

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
236impl<C> Client<DropContextService<hyper::client::Client<hyper::client::HttpConnector, Body>, C>, C>

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
as_strMethod · 0.80
into_base_pathFunction · 0.70
buildMethod · 0.45

Tested by

no test coverage detected