January 2019
Intermediate to advanced
520 pages
14h 32m
English
For POST requests, we need input parameters that will be serialized to the request's body, and output parameters that will be deserialized from the request's response body. Look at the following function:
fn post_request<T, O>(url: &str, params: T) -> impl Future<Item = O, Error = Error>where T: Serialize, O: for <'de> Deserialize<'de> + 'static,{ client::ClientRequest::post(url) .form(params).into_future().and_then(|req| { req.send() .map_err(Error::from).and_then(|resp| { if resp.status().is_success() { let fut = resp.json::<O>().from_err(); boxed(fut) } else { error!("Microservice error: {}", resp.status()); let fut = Err(format_err!("microservice error")) .into_future().from_err(); boxed(fut) } }) })}
The post_request function ...
Read now
Unlock full access