pub struct Response {
pub status: StatusCode,
pub headers: HashMap<String, String>,
/* private fields */
}Expand description
Wrapped HTTP response with convenience methods.
Fields§
§status: StatusCodeResponse status code
headers: HashMap<String, String>Response headers
Implementations§
Source§impl Response
impl Response
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Gets the response status code.
Sourcepub fn status_u16(&self) -> u16
pub fn status_u16(&self) -> u16
Gets the numeric response status code.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Checks if the response status is successful (2xx).
Sourcepub fn header(&self, name: &str) -> Option<&String>
pub fn header(&self, name: &str) -> Option<&String>
Gets a header value by name (case-insensitive).
Sourcepub fn body_bytes(&self) -> &Bytes
pub fn body_bytes(&self) -> &Bytes
Gets the response body as a byte slice.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Consumes the response and returns the body as bytes.
Sourcepub fn text_or_diagnostic(self) -> String
pub fn text_or_diagnostic(self) -> String
Converts the response body to a string, returning a diagnostic marker for non-UTF-8 bodies.
Sourcepub fn json<T: DeserializeOwned>(self) -> AppResult<T>
pub fn json<T: DeserializeOwned>(self) -> AppResult<T>
Parses the response body as JSON.
Sourcepub fn checked_text(self) -> AppResult<String>
pub fn checked_text(self) -> AppResult<String>
Returns the body text after converting non-2xx responses into an AppError.
Sourcepub fn checked_text_with<F>(self, mapper: F) -> AppResult<String>
pub fn checked_text_with<F>(self, mapper: F) -> AppResult<String>
Returns the body text after applying custom non-2xx response mapping.
Sourcepub fn checked_json<T: DeserializeOwned>(self) -> AppResult<T>
pub fn checked_json<T: DeserializeOwned>(self) -> AppResult<T>
Returns the parsed JSON body after converting non-2xx responses into an AppError.
Sourcepub fn checked_json_with<T, F>(self, mapper: F) -> AppResult<T>
pub fn checked_json_with<T, F>(self, mapper: F) -> AppResult<T>
Returns the parsed JSON body after applying custom non-2xx response mapping.
Sourcepub fn error_for_status(self) -> AppResult<Self>
pub fn error_for_status(self) -> AppResult<Self>
Returns an error if the status is not 2xx.
Sourcepub fn error_for_status_with<F>(self, mapper: F) -> AppResult<Self>
pub fn error_for_status_with<F>(self, mapper: F) -> AppResult<Self>
Returns an error if the status is not 2xx, using the supplied response mapper.