pub struct Response { /* private fields */ }Implementations§
Source§impl Response
impl Response
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
The status code (e.g. 200)
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
The final URL. This can differ from the request URL when redirects are followed.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
The header value for the given name, or None if not found.
For historical reasons, the HTTP spec allows for header values to be encoded using encodings like iso-8859-1. Such encodings mean the values are not possible to interpret as utf-8.
In case the header value can’t be read as utf-8, this function also returns None.
Sourcepub fn text(self) -> Result<String, FromUtf8Error>
pub fn text(self) -> Result<String, FromUtf8Error>
Turns the response into a utf-8 encoded String.
If the encoding fails, returns an error.
Sourcepub fn json<T: DeserializeOwned>(self) -> Result<T, Error>
pub fn json<T: DeserializeOwned>(self) -> Result<T, Error>
Deserializes the response into a JSON value.
§Any type
use serde_json::Value;
use flawless_http::get;
let response = get("https://httpbin.org/get").send().unwrap();
let json: Value = response.json().unwrap();
assert_eq!(json["url"].as_str().unwrap(), "https://httpbin.org/get");§Specific type
use std::collections::HashMap;
use flawless_http::get;
#[derive(serde::Deserialize)]
struct BinGet {
args: HashMap<String, String>,
headers: HashMap<String, String>,
origin: String,
url: String
}
let response = get("https://httpbin.org/get").send().unwrap();
let json: BinGet = response.json().unwrap();
assert_eq!(json.url, "https://httpbin.org/get");Trait Implementations§
Source§impl From<HttpResponse> for Response
impl From<HttpResponse> for Response
Source§fn from(value: HttpResponse) -> Self
fn from(value: HttpResponse) -> Self
Converts to this type from the input type.
impl Eq for Response
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more