I use crate reqwest for have request to api.github.com, the code i use this
use reqwest::header::USER_AGENT;
#[tokio::main]
#[allow(unused_variables)]
pub async fn get_user(name_user_github: String) {
let mut uri: String = String::from("https://api.github.com/users/");
uri.push_str(name_user_github.as_str());
uri.push_str("/events");
let client = reqwest::Client::new();
let body = client
.get(uri)
.header(USER_AGENT, "github-user-activity")
.send()
.await
.unwrap()
.text()
.await
.unwrap();
println!("{:?}", body);
}
i like feedback about code for improving and too also use the error,
I'am so sorry for me english.
Thank you for people me can help
For simple use-cases of reqwest, the blocking API might actually be easier to use because you won’t need to handle async fn yourself then.
For the uri, it might be simpler to use format like:
let uri = format!("https://api.github.com/users/{name_user_github}/events");
instead of your 3-line approach.
Moreover, APIs that take a string argument to look at it / further process it most commonly are written with &str in Rust, so
get_user(name_user_github: &str)
would seem more idiomatic 
Handling many cases of Result values from reqwest::Result might actually be more comfortable to achieve even syntactically by just propagating the error rather than unwrap. (You could of course always decide to call unwrap after all at the place where you call your function.)
Note that println!("{:?}", body); offers a newer,
alternative syntax: println!("{body:?}");.
It looks like reqwest has some specific methods for setting user-agent information as a default header for the whole client. All in all, here’s a (untested) rewrite of your snippet:
pub fn get_user(name_user_github: &str) -> reqwest::Result<()> {
let uri = format!("https://api.github.com/users/{name_user_github}/events");
let client = reqwest::blocking::Client::builder()
.user_agent("github-user-activity")
.build()?;
let body: String = client.get(uri).send()?.text()?;
println!("{body:?}");
Ok(())
}
I gave body an explicit type annotation here (: String) because when all we do is Debug-printing it, we wouldn’t be warned if we forgot taking the value out of the Result.
Thank you so much, for responding me post and help me with feedback my function, Your advice was a great help to me
@steffahn Hello
Here is the corrected code. Thank you very much for your advice; it really helped me to handle the errors much better and adapt it to my specific needs.
use crate::model::github_events::Events;
use reqwest::{Result, blocking};
pub fn get_user(name_user_github: String) -> Result<Vec<Events>> {
let uri: String = format!(
"https://api.github.com/users/{name_user_github}/events"
);
let client = blocking::Client::builder()
.user_agent("github-user-activity")
.build()?;
let body = client
.get(uri)
.send()?;
let res: Vec<Events> = body.json()?;
Ok(res)
}