37
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								README.md
									
									
									
									
									
								
							| @@ -14,32 +14,49 @@ An ergonomic, batteries-included HTTP Client for Rust. | |||||||
| - Cookie Store | - Cookie Store | ||||||
| - [Changelog](CHANGELOG.md) | - [Changelog](CHANGELOG.md) | ||||||
|  |  | ||||||
|  |  | ||||||
| ## Example | ## Example | ||||||
|  |  | ||||||
| Async: | This asynchronous example uses [Tokio](https://tokio.rs) and enables some | ||||||
|  | optional features, so your `Cargo.toml` could look like this: | ||||||
|  |  | ||||||
|  | ```toml | ||||||
|  | [dependencies] | ||||||
|  | reqwest = { version = "0.10", features = ["json"] } | ||||||
|  | tokio = { version = "0.2", features = ["full"] } | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | And then the code: | ||||||
|  |  | ||||||
| ```rust,no_run | ```rust,no_run | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
|  |  | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||||
|     let resp: HashMap<String, String> = reqwest::get("https://httpbin.org/ip") |     let resp = reqwest::get("https://httpbin.org/ip") | ||||||
|         .await? |         .await? | ||||||
|         .json() |         .json::<HashMap<String, String>>() | ||||||
|         .await?; |         .await?; | ||||||
|     println!("{:#?}", resp); |     println!("{:#?}", resp); | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Blocking: | ## Blocking Client | ||||||
|  |  | ||||||
|  | There is an optional "blocking" client API that can be enabled: | ||||||
|  |  | ||||||
|  | ```toml | ||||||
|  | [dependencies] | ||||||
|  | reqwest = { version = "0.10", features = ["blocking", "json"] } | ||||||
|  | ``` | ||||||
|  |  | ||||||
| ```rust,no_run | ```rust,no_run | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
|  |  | ||||||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||||
|     let resp: HashMap<String, String> = reqwest::blocking::get("https://httpbin.org/ip")? |     let resp = reqwest::blocking::get("https://httpbin.org/ip")? | ||||||
|         .json()?; |         .json::<HashMap<String, String>>()?; | ||||||
|     println!("{:#?}", resp); |     println!("{:#?}", resp); | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| @@ -55,7 +72,9 @@ On Windows and macOS: | |||||||
|  |  | ||||||
| - Nothing. | - Nothing. | ||||||
|  |  | ||||||
| Reqwest uses [rust-native-tls](https://github.com/sfackler/rust-native-tls), which will use the operating system TLS framework if available, meaning Windows and macOS. On Linux, it will use OpenSSL 1.1. | Reqwest uses [rust-native-tls](https://github.com/sfackler/rust-native-tls), | ||||||
|  | which will use the operating system TLS framework if available, meaning Windows | ||||||
|  | and macOS. On Linux, it will use OpenSSL 1.1. | ||||||
|  |  | ||||||
|  |  | ||||||
| ## License | ## License | ||||||
| @@ -67,4 +86,6 @@ Licensed under either of | |||||||
|  |  | ||||||
| ### Contribution | ### Contribution | ||||||
|  |  | ||||||
| Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. | Unless you explicitly state otherwise, any contribution intentionally submitted | ||||||
|  | for inclusion in the work by you, as defined in the Apache-2.0 license, shall | ||||||
|  | be dual licensed as above, without any additional terms or conditions. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user