pub struct Response { /* private fields */ }Expand description
HTTP response wrapper.
The full body is already buffered in memory as Bytes when you receive this type.
Methods named into_* perform parsing synchronously; the async counterparts
(text, json, …) delegate to into_* without additional I/O and exist for
ergonomics in async code (e.g. RequestBuilder::send_json).
Prefer into_json, into_text, and into_bytes_checked on hot paths.
This model suits typical JSON APIs. For large or chunked bodies, use
StreamingResponse via send_stream.
Implementations§
Source§impl Response
impl Response
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
HTTP status code.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true for 2xx status codes.
Sourcepub fn error_for_status(&self) -> Result<(), Error>
pub fn error_for_status(&self) -> Result<(), Error>
Returns an error if the status is not success.
Sourcepub fn into_text(self) -> Result<String, Error>
pub fn into_text(self) -> Result<String, Error>
Reads the body as UTF-8 after checking for a success status.
Prefer this over text when you do not need an .await (no extra I/O).
Sourcepub async fn text(self) -> Result<String, Error>
pub async fn text(self) -> Result<String, Error>
Async alias for into_text; does not perform additional I/O.
Sourcepub fn into_bytes_checked(self) -> Result<Bytes, Error>
pub fn into_bytes_checked(self) -> Result<Bytes, Error>
Returns the body after checking for a success status.
Prefer this over bytes_checked on hot paths.
Sourcepub async fn bytes_checked(self) -> Result<Bytes, Error>
pub async fn bytes_checked(self) -> Result<Bytes, Error>
Async alias for into_bytes_checked.
Sourcepub fn into_json<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn into_json<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
Deserializes JSON after checking for a success status, using the client or request
JsonParserFn when configured.
Prefer this over json on hot paths. See crate::json_parser for the
default single-step path vs a custom two-step parser.
Sourcepub async fn json<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn json<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
Async alias for into_json.
Sourcepub fn into_json_with<T, F>(self, parse: F) -> Result<T, Error>
pub fn into_json_with<T, F>(self, parse: F) -> Result<T, Error>
Deserializes JSON in one step with a custom closure (Bytes → T).
Ignores any client- or request-level JsonParserFn.
Use this for BOM stripping or other transforms without the Value intermediate
required by ClientBuilder::json_parser.
Sourcepub async fn json_with<T, F>(self, parse: F) -> Result<T, Error>
pub async fn json_with<T, F>(self, parse: F) -> Result<T, Error>
Async alias for into_json_with.
Sourcepub fn into_json_unchecked<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn into_json_unchecked<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
Deserializes JSON without checking HTTP status, using the configured JsonParserFn when set.
Sourcepub async fn json_unchecked<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn json_unchecked<T>(self) -> Result<T, Error>where
T: DeserializeOwned,
Async alias for into_json_unchecked.
Sourcepub fn into_parts(self) -> (StatusCode, HeaderMap, Bytes)
pub fn into_parts(self) -> (StatusCode, HeaderMap, Bytes)
Splits into status, headers, and body.
Sourcepub fn body_by_content_type(&self) -> ResponseBodyKind
pub fn body_by_content_type(&self) -> ResponseBodyKind
Classifies the body using the Content-Type header (does not check HTTP status).
Sourcepub fn into_body_by_content_type(self) -> Result<ResponseBodyKind, Error>
pub fn into_body_by_content_type(self) -> Result<ResponseBodyKind, Error>
Like body_by_content_type after verifying a 2xx status.
Trait Implementations§
Source§impl ApiResponseExt for Response
Available on crate feature json only.
impl ApiResponseExt for Response
json only.Source§fn into_api_result<T, E>(self) -> Result<Result<T, E>, Error>where
T: DeserializeOwned,
E: DeserializeOwned,
fn into_api_result<T, E>(self) -> Result<Result<T, E>, Error>where
T: DeserializeOwned,
E: DeserializeOwned,
into_api_result.