MCPcopy Create free account
hub / github.com/actix/examples / step_x

Function step_x

json/json-validation/src/main.rs:42–63  ·  view source on GitHub ↗

validate data, post json to httpbin, get it back in the response body, return deserialized

(data: SomeData, client: &Client)

Source from the content-addressed store, hash-verified

40
41/// validate data, post json to httpbin, get it back in the response body, return deserialized
42async fn step_x(data: SomeData, client: &Client) -> actix_web::Result<SomeData> {
43 // validate data
44 data.validate().map_err(ErrorBadRequest)?;
45
46 let mut res = client
47 .post("https://httpbin.org/post")
48 .send_json(&data)
49 .await
50 // <- convert SendRequestError to an InternalError, a type that implements the ResponseError trait
51 .map_err(actix_web::error::ErrorInternalServerError)?; // <- convert it into an actix_web::Error
52
53 let mut body = BytesMut::new();
54 while let Some(chunk) = res.next().await {
55 body.extend_from_slice(&chunk?);
56 }
57
58 let body = serde_json::from_slice::<HttpBinResponse>(&body).unwrap();
59
60 println!("{body:?}");
61
62 Ok(body.json)
63}
64
65async fn create_something(
66 some_data: web::Json<SomeData>,

Callers 1

create_somethingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected