Function get

Source
pub fn get<T, U>(uri: T, writer: &mut U) -> Result<Response, Error>
where T: AsRef<str>, U: Write,
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?
examples/chunked.rs (line 6)
3fn main() {
4    // Sends a HTTP GET request and processes the response.
5    let mut body = Vec::new();
6    let res = request::get("https://jigsaw.w3.org/HTTP/ChunkedScript", &mut body).unwrap();
7
8    // Prints details about the response.
9    println!("Status: {} {}", res.status_code(), res.reason());
10    println!("Headers: {}", res.headers());
11    //println!("{}", String::from_utf8_lossy(&body));
12}
More examples
Hide additional 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}