[][src]Function lab_grader::helpers::web::get

pub fn get(url: &str) -> Result<Response, Error>

Performs a GET request

If there is an error in sending the request, this will return with and Err variant.

If the request is performed, an Ok variant will return containing a Response. This Response could have an error code like 500 or 404. This is different from the request not being performed.

Example

use lab_grader::helpers::web::get;

let result = get("https://postman-echo.com/get");

if let Ok(resp) = result {
    // Request was successful, deal with the response
    assert!(resp.status().is_success());
} else {
    // The request failed to go through, deal with that
}

Get the body of data returned from a GET request


let result = get("https://postman-echo.com/get");

// If the request went through and returned
if let Ok(resp) = result {
    // If the request contains a body of text
    if let Ok(body) = resp.text() {
        assert!(body.contains("postman-echo.com"));
    } else {
        // Couldn't get the body from the request
    }
}