|
5 | 5 | //! are not handled at this level. This module provides the building blocks to |
6 | 6 | //! customize those things externally. |
7 | 7 | //! |
8 | | -//! If you are looking for a convenient HTTP client, |
9 | | -//! then you may wish to consider [reqwest](https://github.com/seanmonstar/reqwest) |
10 | | -//! for a high level client or [`hyper-util`'s client](https://docs.rs/hyper-util/latest/hyper_util/client/index.html) |
| 8 | +//! If you are looking for a convenient HTTP client, then you may wish to |
| 9 | +//! consider [reqwest](https://github.com/seanmonstar/reqwest) for a high level |
| 10 | +//! client or [`hyper-util`'s client](https://docs.rs/hyper-util/latest/hyper_util/client/index.html) |
11 | 11 | //! if you want to keep it more low level / basic. |
12 | 12 | //! |
13 | 13 | //! ## Example |
14 | 14 | //! |
15 | | -//! A simple example that uses the `SendRequest` struct to talk HTTP over some TCP stream. |
16 | | -//! |
17 | | -//! ```no_run |
18 | | -//! # #[cfg(all(feature = "client", feature = "http1"))] |
19 | | -//! # mod rt { |
20 | | -//! use bytes::Bytes; |
21 | | -//! use http::{Request, StatusCode}; |
22 | | -//! use http_body_util::Empty; |
23 | | -//! use hyper::client::conn; |
24 | | -//! # use hyper::rt::{Read, Write}; |
25 | | -//! # async fn run<I>(tcp: I) -> Result<(), Box<dyn std::error::Error>> |
26 | | -//! # where |
27 | | -//! # I: Read + Write + Unpin + Send + 'static, |
28 | | -//! # { |
29 | | -//! let (mut request_sender, connection) = conn::http1::handshake(tcp).await?; |
30 | | -//! |
31 | | -//! // spawn a task to poll the connection and drive the HTTP state |
32 | | -//! tokio::spawn(async move { |
33 | | -//! if let Err(e) = connection.await { |
34 | | -//! eprintln!("Error in connection: {}", e); |
35 | | -//! } |
36 | | -//! }); |
37 | | -//! |
38 | | -//! let request = Request::builder() |
39 | | -//! // We need to manually add the host header because SendRequest does not |
40 | | -//! .header("Host", "example.com") |
41 | | -//! .method("GET") |
42 | | -//! .body(Empty::<Bytes>::new())?; |
43 | | -//! |
44 | | -//! let response = request_sender.send_request(request).await?; |
45 | | -//! assert!(response.status() == StatusCode::OK); |
46 | | -//! |
47 | | -//! let request = Request::builder() |
48 | | -//! .header("Host", "example.com") |
49 | | -//! .method("GET") |
50 | | -//! .body(Empty::<Bytes>::new())?; |
51 | | -//! |
52 | | -//! let response = request_sender.send_request(request).await?; |
53 | | -//! assert!(response.status() == StatusCode::OK); |
54 | | -//! # Ok(()) |
55 | | -//! # } |
56 | | -//! # } |
57 | | -//! ``` |
| 15 | +//! See the [client guide](https://hyper.rs/guides/1/client/basic/). |
58 | 16 |
|
59 | 17 | #[cfg(feature = "http1")] |
60 | 18 | pub mod http1; |
|
0 commit comments