pub struct Response<T = Value> { /* private fields */ }Expand description
A successful response. T is the type json decodes into.
Non-success statuses never reach this type; send
turns them into Error::Api. A failure while reading the body keeps the
status and headers: Error::Body for an interrupted body and
Error::ResponseTooLarge above the transport limit.
The body is read only when a consuming method is called. Choose one reader; capture any headers needed afterward before consuming the response. A successful HTTP status alone does not establish that the body is valid or an import fully succeeded.
Implementations§
Source§impl<T> Response<T>
impl<T> Response<T>
pub fn status_code(&self) -> StatusCode
pub fn headers(&self) -> &HeaderMap
pub fn content_length(&self) -> Option<u64>
Sourcepub async fn bytes(self) -> Result<Bytes>
pub async fn bytes(self) -> Result<Bytes>
Reads the whole body, failing with Error::ResponseTooLarge above the transport limit.
Sourcepub async fn text(self) -> Result<String>
pub async fn text(self) -> Result<String>
Reads the body as UTF-8, replacing invalid sequences.
Sourcepub fn bytes_stream(self) -> impl Stream<Item = Result<Bytes>> + Send
pub fn bytes_stream(self) -> impl Stream<Item = Result<Bytes>> + Send
Streams the body without the transport’s size limit. Failures return
Error::Body with the status, headers and number of bytes delivered
before the failure. No body trace event is emitted.
Sourcepub async fn json_as<U: DeserializeOwned>(self) -> Result<U>
pub async fn json_as<U: DeserializeOwned>(self) -> Result<U>
Decodes the body into a type other than the endpoint’s default.
Source§impl<T: DeserializeOwned> Response<T>
impl<T: DeserializeOwned> Response<T>
Sourcepub async fn json(self) -> Result<T>
pub async fn json(self) -> Result<T>
Reads and decodes the body into the endpoint’s response type.
Invalid JSON or a mismatched shape returns Error::Decode with response
status and headers. Reading remains subject to the transport’s size limit.