pub fn get<T, U>(uri: T, writer: &mut U) -> Result<Response, Error>Expand description
Creates and sends a GET request. Returns the response for this request.
ยงExamples
use http_req::request;
let mut writer = Vec::new();
const uri: &str = "https://www.rust-lang.org/learn";
let response = request::get(uri, &mut writer).unwrap();Examples found in repository?
More examples
examples/get.rs (line 8)
3fn main() {
4 // Container for body of a response.
5 let mut body = Vec::new();
6
7 // Sends a HTTP GET request and processes the response. Saves body of the response to `body` variable.
8 let res = request::get("https://www.rust-lang.org/learn", &mut body).unwrap();
9
10 //Prints details about the response.
11 println!("Status: {} {}", res.status_code(), res.reason());
12 println!("Headers: {}", res.headers());
13 //println!("{}", String::from_utf8_lossy(&body));
14}