Skip to content

Instantly share code, notes, and snippets.

@oparaskos
Last active June 13, 2021 19:56
Show Gist options
  • Save oparaskos/bcd2229d455eb00e09d898005f8139b3 to your computer and use it in GitHub Desktop.
Save oparaskos/bcd2229d455eb00e09d898005f8139b3 to your computer and use it in GitHub Desktop.
Rust reqwest/tokio minimal example
/*** Cargo.toml
[dependencies]
futures = "0.3.15"
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
*/
// main.rs
use reqwest;
async fn do_thing() -> Result<(), reqwest::Error> {
let body = reqwest::get("https://www.rust-lang.org")
.await?
.text()
.await?;
println!("body = {:?}", body);
return Ok(());
}
#[tokio::main]
async fn main() {
let result = do_thing().await;
match result {
Ok(_) => (),
Err(e) => println!("Something went wrong! {:?}", e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment