How to make an HTTP request in Rust? No built-in function?
Hi! I just started learning Rust after Python and JavaScript, and I ran into a problem. In Python, I'm used to writing `requests.get(url)`, and it just works. In Rust, I expected to find something similar in the standard library, but apparently it's not there.
I tried to make a simple GET request to a public API using only the standard library, but nothing worked. Here's my code, which obviously doesn't compile:
```rust
use std::net::TcpStream;
use std::io::Read;
fn main() {
let mut response = String::new();
let mut stream = TcpStream::connect("http://api.example.com/data").unwrap();
stream.read_to_string(&mut response).unwrap();
println!("{}", response);
}
```
The error says something about the protocol and lack of HTTP support. I understand that Rust is a systems language,
No answers yet.
Log in to leave an answer