Skip to content

Instantly share code, notes, and snippets.

@fcroiseaux
Created January 27, 2021 21:35
Show Gist options
  • Save fcroiseaux/9758135d5c1f5371873ff17768a802b2 to your computer and use it in GitHub Desktop.
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
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