Hello! I'm a newbie in Rust and I just need a little help if possible because I'm in trouble...
I'm trying to have a Rust server to listen on an IP address.
When the server got a GET request, I want to send this GET request to the github API and then return the result on the web page.
In this code I'm trying to send the request to https://api.github.com/users/octocat and just display the json response on the web page.
How can I display the result on the web page?
How can I change the user when I am requesting the server?
I tried to mix things I found on the internet, but my code is broken ^^' So if you can give me some advices to work on it it would be very helpful!
async fn get_function(user : String) -> Result<impl warp::Reply, warp::Rejection> {
let address = String::from("https://api.github.com/users/");
let HttpRequest = [address, user].concat();
let resp = reqwest::Client::new()
.get(HttpRequest)
.send()
.await?
.json::<std::collections::HashMap<String, String>>()
.await?;
println!("{:#?}", resp);
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let user = String::from("octocat");
let get_request = warp::get().and(get_function(user));
warp::serve(get_request)
.run(([127, 0, 0, 1], 3030))
.await;
Ok(())
}