-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from sagebind/readme-example-updates
Expand first readme example to full program
- Loading branch information
Showing
8 changed files
with
84 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Another simple example that creates a custom HTTP client instance and sends | ||
//! a GET request with it instead of using the default client. | ||
use isahc::{ | ||
config::RedirectPolicy, | ||
prelude::*, | ||
}; | ||
use std::{ | ||
io::{copy, stdout}, | ||
time::Duration, | ||
}; | ||
|
||
fn main() -> Result<(), isahc::Error> { | ||
// Create a custom client instance and customize a couple things different | ||
// than the default settings. Check the documentation of `HttpClient` and | ||
// `Configurable` for everything that can be customized. | ||
let client = HttpClient::builder() | ||
.timeout(Duration::from_secs(5)) | ||
.redirect_policy(RedirectPolicy::Follow) | ||
.build()?; | ||
|
||
let mut response = client.get("https://rust-lang.org")?; | ||
|
||
// Copy the response body directly to stdout. | ||
copy(response.body_mut(), &mut stdout())?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters