validate data, post json to httpbin, get it back in the response body, return deserialized
(data: SomeData, client: &Client)
| 40 | |
| 41 | /// validate data, post json to httpbin, get it back in the response body, return deserialized |
| 42 | async 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 | |
| 65 | async fn create_something( |
| 66 | some_data: web::Json<SomeData>, |