Created
January 27, 2021 21:35
-
-
Save fcroiseaux/9758135d5c1f5371873ff17768a802b2 to your computer and use it in GitHub Desktop.
Example of an actix http client request that return sa string containing the body of the response
This file contains hidden or 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
let url = "https://site.com/endpoint"; | |
let client = Client::default(); | |
let response :String = match client | |
.get(url) | |
.send() | |
.await { | |
Ok(mut resp) => match resp.body().await { | |
Ok(r) => String::from_utf8(r.to_vec()).unwrap_or_default(), | |
Err(e) => { | |
println!("{}", e); | |
String::new() | |
} | |
}, | |
Err(e1) => { | |
println!("{}", e1); | |
String::new() | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment