typestar

An HTTP GET in Rust

reqwest's async client: send the request, await the body.

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let body = reqwest::get("https://typestar.io/healthz")
        .await?
        .text()
        .await?;

    println!("{} bytes", body.len());
    println!("{}", body.trim());
    Ok(())
}

How it works

  1. get builds and sends in one call.
  2. text awaits the whole body as a String.
  3. Both the request and the body read are await points.

Keywords and builtins used here

The run, in numbers

Lines
11
Characters to type
215
Tokens
73
Three-star pace
110 tpm

At the three-star pace of 110 tokens a minute, this run takes about 40 seconds.

Type this snippet

Step 1 of 5 in Requests with reqwest, step 7 of 12 in CLI tools & HTTP clients.

← Previous Next →