Struct edjx::FetchResponse
source · pub struct FetchResponse { /* private fields */ }
Expand description
Response for HTTP fetch request, which may include body, headers, and status code.
use edjx::{FetchResponse, HttpFetch, StatusCode, Uri};
use std::str::FromStr;
let fetch_uri = Uri::from_str("https://httpbin.org/get").unwrap();
let mut fetch_res: FetchResponse = match HttpFetch::get(fetch_uri).send() {
Ok(resp) => resp,
Err(e) => {
panic!("{}", &e.to_string());
}
};
let body = fetch_res.read_body();
assert_eq!(fetch_res.status_code(), &StatusCode::OK);
Implementations§
source§impl FetchResponse
impl FetchResponse
sourcepub fn status_code(&self) -> &StatusCode
pub fn status_code(&self) -> &StatusCode
Returns the HTTP status code of the fetch response.
sourcepub fn read_body(&mut self) -> Result<Vec<u8>, StreamError>
pub fn read_body(&mut self) -> Result<Vec<u8>, StreamError>
Reads and returns the HTTP body of the fetch response.
This method should not be called more than once.
sourcepub fn get_read_stream(&mut self) -> &mut ReadStream
pub fn get_read_stream(&mut self) -> &mut ReadStream
Returns the HTTP body of the fetch response as a read stream.