Struct simplist::HttpSyncResponse
[−]
[src]
pub struct HttpSyncResponse { /* fields omitted */ }
a http response, whose body can be read synchronously.
there are two primary methods to retrieve the body for a response:
fn read_as_bytes(...)
: returns aResult<Vec<u8>, HttpError>
that contains the response body.fn read_as_string(...)
: returns aResult<String, HttpError>
that contains the response body.
usage
instances of this struct are returned by invoking one of the
HttpSyncClient::request
's methods.
use simplist::HttpMethod; use simplist::HttpResponse; use simplist::HttpSyncClient; let url = "https://hinaria.com".parse()?; let http = HttpSyncClient::new(...); let request = HttpRequest::with(url, HttpMethod::Get); let response = http.request(request)?; let string = response.read_as_string(); println!("{:?}", string) // => Ok("<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\"> ...")
Methods
impl HttpSyncResponse
[src]
fn headers(&self) -> &Headers
[src]
returns the http headers for this response.
examples
use hyper::Headers; use simplist::HttpSyncClient; use simplist::HttpMethod; use simplist::HttpRequest; let url = "https://hinaria.com".parse()?; let http = HttpSyncClient::new(...); let request = HttpRequest::with(url, HttpMethod::Get); let response = await http.request(request)?; let headers = response.headers(); assert_eq!(headers.has::<ContentType>(), true);
fn status(&self) -> StatusCode
[src]
returns the status code for this response.
examples
use hyper::status::StatusCode; use simplist::HttpMethod; use simplist::HttpRequest; use simplist::HttpSyncClient; let url = "https://hinaria.com".parse()?; let http = HttpSyncClient::new(...); let request = HttpRequest::with(url, HttpMethod::Get); let response = http.request(request)?; assert_eq!(response.status(), StatusCode::Ok);
fn status_code(&self) -> u16
[src]
returns the status code for as a u16
.
examples
use simplist::HttpMethod; use simplist::HttpRequest; use simplist::HttpSyncClient; let url = "https://hinaria.com".parse()?; let http = HttpSyncClient::new(...); let request = HttpRequest::with(url, HttpMethod::Get); let response = http.request(request)?; assert_eq!(response.status_code(), 200);
fn read_as_bytes(self) -> Result<Vec<u8>, HttpError>
[src]
reads this response, returning a Vec<u8>
.
examples
use simplist::HttpMethod; use simplist::HttpRequest; use simplist::HttpSyncClient; let url = "https://hinaria.com".parse()?; let http = HttpSyncClient::new(...); let request = HttpRequest::with(url, HttpMethod::Get); let response = http.request(request)?; let data = await response.read_as_bytes(); println!("{:?}", data) // => Ok([60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...])
fn read_as_string(self) -> Result<String, HttpError>
[src]
reads this response, returning a String
.
examples
use simplist::HttpMethod; use simplist::HttpRequest; use simplist::HttpSyncClient; let url = "https://hinaria.com".parse()?; let http = HttpSyncClient::new(...); let request = HttpRequest::with(url, HttpMethod::Get); let response = http.request(request)?; let string = response.read_as_string(); println!("{:?}", string) // => Ok("<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\"> ...")