How to make an HTTP request in Rust?
Hello everyone! I started learning Rust and encountered the task of making an HTTP request. I need to send a GET request to an external API and get a JSON response. I tried using the standard library, but as I understand, it doesn't have a built-in HTTP client.
I tried writing something like this:
use std::io::Read;\n\nfn main() {\n let mut response = reqwest::blocking::get("https://api.example.com/data").unwrap();\n let mut body = String::new();\n response.read_to_string(&mut body).unwrap();\n println!("{}", body);\n}\nBut I get an error: error[E0432]: unresolved import 'reqwest'. Apparently, I need to add a dependency in Cargo.toml. How do I properly add the reqwest crate? What alternatives exist? I'm interested in the asynchronous version (tokio + reqwest).