async/request: add a basic example for send()

This commit is contained in:
Luca Bruno
2019-02-15 09:20:46 +00:00
committed by Sean McArthur
parent 8b62f47ac3
commit 0c84e6b9e9

View File

@@ -324,6 +324,26 @@ impl RequestBuilder {
/// ///
/// This method fails if there was an error while sending request, /// This method fails if there was an error while sending request,
/// redirect loop was detected or redirect limit was exhausted. /// redirect loop was detected or redirect limit was exhausted.
///
/// # Example
///
/// ```no_run
/// # extern crate futures;
/// # extern crate reqwest;
/// #
/// # use reqwest::Error;
/// # use futures::future::Future;
/// #
/// # fn run() -> Result<(), Error> {
/// let response = reqwest::r#async::Client::new()
/// .get("https://hyper.rs")
/// .send()
/// .map(|resp| println!("status: {}", resp.status()));
///
/// let mut rt = tokio::runtime::current_thread::Runtime::new().expect("new rt");
/// rt.block_on(response)
/// # }
/// ```
pub fn send(self) -> impl Future<Item = Response, Error = ::Error> { pub fn send(self) -> impl Future<Item = Response, Error = ::Error> {
match self.request { match self.request {
Ok(req) => self.client.execute(req), Ok(req) => self.client.execute(req),