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

Method config_network_get

api-server/src/client/mod.rs:402–480  ·  view source on GitHub ↗
(&self, context: &C)

Source from the content-addressed store, hash-verified

400 }
401
402 async fn config_network_get(&self, context: &C) -> Result<ConfigNetworkGetResponse, ApiError> {
403 let mut client_service = self.client_service.clone();
404 let mut uri = format!("{}/ceramic/config/network", self.base_path);
405
406 // Query parameters
407 let query_string = {
408 let mut query_string = form_urlencoded::Serializer::new("".to_owned());
409 query_string.finish()
410 };
411 if !query_string.is_empty() {
412 uri += "?";
413 uri += &query_string;
414 }
415
416 let uri = match Uri::from_str(&uri) {
417 Ok(uri) => uri,
418 Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))),
419 };
420
421 let mut request = match Request::builder()
422 .method("GET")
423 .uri(uri)
424 .body(Body::empty())
425 {
426 Ok(req) => req,
427 Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))),
428 };
429
430 let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
431 request.headers_mut().insert(
432 HeaderName::from_static("x-span-id"),
433 match header {
434 Ok(h) => h,
435 Err(e) => {
436 return Err(ApiError(format!(
437 "Unable to create X-Span ID header value: {}",
438 e
439 )))
440 }
441 },
442 );
443
444 let response = client_service
445 .call((request, context.clone()))
446 .map_err(|e| ApiError(format!("No response received: {}", e)))
447 .await?;
448
449 match response.status().as_u16() {
450 200 => {
451 let body = response.into_body();
452 let body = body
453 .into_raw()
454 .map_err(|e| ApiError(format!("Failed to read response: {}", e)))
455 .await?;
456 let body = str::from_utf8(&body)
457 .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
458 let body = serde_json::from_str::<models::NetworkInfo>(body).map_err(|e| {
459 ApiError(format!("Response body did not match the schema: {}", e))

Callers 1

runMethod · 0.45

Calls 9

newFunction · 0.85
as_strMethod · 0.80
statusMethod · 0.80
getFunction · 0.50
cloneMethod · 0.45
finishMethod · 0.45
is_emptyMethod · 0.45
insertMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected