pub struct Response { /* private fields */ }Expand description
A response, as a transport answers one: the status, headers and URL are here, and the body is read on demand.
The send loop decides on the head, releases the attempt’s permit, and only
then reads an error’s body, so a slow body holds no slot. Reading consumes
the response: bytes, text and
json each return an ApiError, a transport failure
(ApiError::Transport) or, for the last, a body that does not parse
(ApiError::Serialization).
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(
status: StatusCode,
headers: HeaderMap,
url: Url,
body: BoxFuture<Result<Bytes, TransportError>>,
) -> Self
pub fn new( status: StatusCode, headers: HeaderMap, url: Url, body: BoxFuture<Result<Bytes, TransportError>>, ) -> Self
A response with its head and a future that reads its body.
url is the URL the response answers, after any redirect the
transport followed.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
The status.
Sourcepub async fn text(self) -> Result<String, ApiError>
pub async fn text(self) -> Result<String, ApiError>
Read the body as text: UTF-8, with each invalid sequence replaced by
U+FFFD.
§Errors
ApiError::Transport when the body could not be read.
Sourcepub async fn json<T: DeserializeOwned>(self) -> Result<T, ApiError>
pub async fn json<T: DeserializeOwned>(self) -> Result<T, ApiError>
Read the body and parse it as JSON.
§Errors
ApiError::Transport when the body could not be read, and
ApiError::Serialization when it does not parse as T.