Skip to content

Commit d96a1b3

Browse files
tottotoseanmonstar
authored andcommitted
guide: update basic client guide
1 parent 39bf4fc commit d96a1b3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

_stable/client/basic.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ but the point here is just to show all the setup required. Once you have this,
4040
you are set to make thousands of client requests efficiently.
4141

4242
We have to setup some sort of runtime. You can use whichever async runtime you'd
43-
like, but for this guide we're going to use tokio. If you've never used futures
43+
like, but for this guide we're going to use tokio. If you've never used futures
4444
in Rust before, you may wish to read through [Tokio's guide on Futures][Tokio-Futures].
4545

4646
```rust
@@ -59,19 +59,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
5959
## Setup
6060

6161
To get started we'll need to get a few things setup. For this guide we're
62-
going to send a GET [`Request`][Request] to [http://httpbin.org/ip](http://httpbin.org/ip),
63-
which will return a `200 OK` and the Requester's IP address in the body.
62+
going to send a GET [`Request`][Request] to [http://httpbin.org/ip](http://httpbin.org/ip),
63+
which will return a `200 OK` and the Requester's IP address in the body.
6464

6565
We need to open a TCP connection to the remote host using a hostname and port,
6666
which in this case is `httpbin.org` and the default port for HTTP: `80`. With our
6767
connection opened, we pass it in to the `client::conn::http1::handshake` function,
68-
performing a handshake to verify the remote is ready to receive our requests.
68+
performing a handshake to verify the remote is ready to receive our requests.
6969

7070
A successful handshake will give us a [Connection][Connection] future that processes
71-
all HTTP state, and a [SendRequest][SendRequest] struct that we can use to send our
72-
`Request`s on the connection.
71+
all HTTP state, and a [SendRequest][SendRequest] struct that we can use to send our
72+
`Request`s on the connection.
7373

74-
To start driving the HTTP state we have to poll the `Connection`, so to finish our
74+
To start driving the HTTP state we have to poll the `Connection`, so to finish our
7575
setup we'll spawn a `tokio::task` and `await` it.
7676

7777
```rust
@@ -123,12 +123,12 @@ tokio::task::spawn(async move {
123123

124124
## GET
125125

126-
Now that we've set up our connection, we're ready to construct and send our first `Request`!
127-
Since `SendRequest` doesn't require absolute-form `URI`s we are required to include a `HOST`
126+
Now that we've set up our connection, we're ready to construct and send our first `Request`!
127+
Since `SendRequest` doesn't require absolute-form `URI`s we are required to include a `HOST`
128128
header in our requests. And while we can send our `Request` with an empty `Body`, we need to
129129
explicitly set it, which we'll do with the [`Empty`][Empty] utility struct.
130130

131-
All we need to do now is pass the `Request` to `SendRequest::send_request`, this returns a
131+
All we need to do now is pass the `Request` to `SendRequest::send_request`, this returns a
132132
future which will resolve to the [`Response`][Response] from `httpbin.org`. We'll print the
133133
status of the response to see that it returned the expected `200 OK` status.
134134

@@ -179,7 +179,7 @@ We know that sending a GET `Request` to `httpbin.org/ip` will return our IP addr
179179
the `Response` body. To see the returned body, we'll simply write it to `stdout`.
180180

181181
Bodies in hyper are asynchronous streams of [`Frame`][Frame]s, so we don't have to wait for the
182-
whole body to arrive, buffering it into memory, and then writing it out. We can simply
182+
whole body to arrive, buffering it into memory, and then writing it out. We can simply
183183
`await` each `Frame` and write them directly to `stdout` as they arrive!
184184

185185
In addition to importing `stdout`, we'll need to make use of the `BodyExt` trait:
@@ -188,7 +188,7 @@ In addition to importing `stdout`, we'll need to make use of the `BodyExt` trait
188188
# extern crate http_body_util;
189189
# extern crate tokio;
190190
use http_body_util::BodyExt;
191-
use tokio::io::{stdout, AsyncWriteExt as _};
191+
use tokio::io::{AsyncWriteExt as _, self};
192192
```
193193

194194
```rust
@@ -225,7 +225,7 @@ use tokio::io::{stdout, AsyncWriteExt as _};
225225
while let Some(next) = res.frame().await {
226226
let frame = next?;
227227
if let Some(chunk) = frame.data_ref() {
228-
io::stdout().write_all(&chunk).await?;
228+
io::stdout().write_all(chunk).await?;
229229
}
230230
}
231231
# Ok(())

0 commit comments

Comments
 (0)