January 2019
Intermediate to advanced
520 pages
14h 32m
English
To send GET requests, we create a get_request function that expects a url parameter and returns a Future instance with binary data:
fn get_request(url: &str) -> impl Future<Item = Vec<u8>, Error = Error> { client::ClientRequest::get(url) .finish().into_future() .and_then(|req| { req.send() .map_err(Error::from) .and_then(|resp| resp.body().from_err()) .map(|bytes| bytes.to_vec()) })}
We use ClientRequestBuilder to create the ClientRequest instance. The ClientRequest struct already has shortcuts that create builders with a preset HTTP method. We call the get method that only sets the Method::GET value to a request that is implemented as the calling method of the ClientRequestBuilder instance. You can also use a builder to set ...
Read now
Unlock full access