Last active
June 13, 2021 19:56
-
-
Save oparaskos/bcd2229d455eb00e09d898005f8139b3 to your computer and use it in GitHub Desktop.
Rust reqwest/tokio minimal example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** 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