pub struct Response<T, F = JsonFormat> { /* private fields */ }Expand description
A typed fully-buffered HTTP response.
The type parameter T is a marker type that indicates what the caller should expect to be able to deserialize the body into.
Service client methods should return a Response<SomeModel> where SomeModel is the service-specific response type.
For example, a service client method that returns a list of secrets should return Response<ListSecretsResponse>.
The type parameter F is a marker type that indicates the format of the data, defaulting to JSON.
XML is supported, and NoFormat indicates a binary body or no body expected e.g., for HTTP 204.
Given a Response<T, F>, a user can deserialize the body formatted as type F into the intended body type T by calling Response::into_model;
however, because the type T is just a marker type, you can also access the raw ResponseBody using Response::into_body.
Implementations§
Source§impl<T, F> Response<T, F>
impl<T, F> Response<T, F>
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the status code from the response.
Sourcepub fn body(&self) -> &ResponseBody
pub fn body(&self) -> &ResponseBody
Get the ResponseBody.
Sourcepub fn deconstruct(self) -> (StatusCode, Headers, ResponseBody)
pub fn deconstruct(self) -> (StatusCode, Headers, ResponseBody)
Deconstruct the HTTP response into its components.
Sourcepub fn into_body(self) -> ResponseBody
pub fn into_body(self) -> ResponseBody
Get the ResponseBody.
Sourcepub fn to_raw_response(&self) -> RawResponse
pub fn to_raw_response(&self) -> RawResponse
Create a RawResponse by cloning borrowed data.
Source§impl<T, F> Response<T, F>where
T: DeserializeWith<F>,
F: Format,
impl<T, F> Response<T, F>where
T: DeserializeWith<F>,
F: Format,
Sourcepub fn into_model(self) -> Result<T, Error>
pub fn into_model(self) -> Result<T, Error>
Fetches the entire body and tries to convert it into type T.
This is the preferred method for parsing the body of a service response into it’s default model type.
§Examples
let secret_client = create_secret_client();
let response = secret_client.get_secret().await;
assert_eq!(response.status(), StatusCode::Ok);
let model = response.into_model().unwrap();
assert_eq!(model.name, "database_password");
assert_eq!(model.value, "hunter2");