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. It does not stream large downloads; use reqwest directly when you need chunked bodies or custom size limits.
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<()>
pub fn error_for_status(&self) -> Result<()>
Returns an error if the status is not success.
Sourcepub fn into_text(self) -> Result<String>
pub fn into_text(self) -> Result<String>
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>
pub async fn text(self) -> Result<String>
Async alias for into_text; does not perform additional I/O.
Sourcepub fn into_bytes_checked(self) -> Result<Bytes>
pub fn into_bytes_checked(self) -> Result<Bytes>
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>
pub async fn bytes_checked(self) -> Result<Bytes>
Async alias for into_bytes_checked.
Sourcepub fn into_json<T: DeserializeOwned>(self) -> Result<T>
pub fn into_json<T: DeserializeOwned>(self) -> Result<T>
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: DeserializeOwned>(self) -> Result<T>
pub async fn json<T: DeserializeOwned>(self) -> Result<T>
Async alias for into_json.
Sourcepub fn into_json_with<T, F>(self, parse: F) -> Result<T>
pub fn into_json_with<T, F>(self, parse: F) -> Result<T>
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>
pub async fn json_with<T, F>(self, parse: F) -> Result<T>
Async alias for into_json_with.
Sourcepub fn into_json_unchecked<T: DeserializeOwned>(self) -> Result<T>
pub fn into_json_unchecked<T: DeserializeOwned>(self) -> Result<T>
Deserializes JSON without checking HTTP status, using the configured JsonParserFn when set.
Sourcepub async fn json_unchecked<T: DeserializeOwned>(self) -> Result<T>
pub async fn json_unchecked<T: DeserializeOwned>(self) -> Result<T>
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.