concept http GET request in category rust
appears as: n HTTP GET request

This is an excerpt from Manning's book Rust in Action.
Listing 8. 9. Using the Rust standard library to construct an HTTP GET request using
std::net::TcpStream(ch8/ch8-stdlib/src/main.rs)use std::io::prelude::*; use std::net::TcpStream; fn main() -> std::io::Result<()> { let mut connection = TcpStream::connect("www.rustinaction.com:80")?; #1 connection.write_all(b"GET / HTTP/1.0")?; #2 connection.write_all(b"\r\n")?; #3 connection.write_all(b"Host: www.rustinaction.com")?; #4 connection.write_all(b"\r\n\r\n")?; #5 std::io::copy(&mut connection, &mut std::io::stdout())?; #6 Ok(()) }
If you’ve ever done any web programming, Listing 8. 5 should be straight forward.
reqwest::get()issues an HTTP GET request to the URL represented byurl. Theresponsevariable holds a struct representing the server’s response. Theresponse.text()method returns aResultthat provides access to the HTTP body, after validating that the contents are a legalString.