Skip to main content

typeway_client/
typed_response.rs

1//! The [`TypedResponse`] wrapper — a deserialized body paired with HTTP metadata.
2
3use http::header::HeaderValue;
4use http::{HeaderMap, StatusCode};
5
6/// A response with both the deserialized body and HTTP metadata.
7///
8/// Returned by [`Client::call_full`](crate::Client::call_full) and
9/// [`RequestBuilder::send_full`](crate::RequestBuilder::send_full).
10///
11/// # Example
12///
13/// ```ignore
14/// let resp = client.call_full::<GetUserEndpoint>((42u32,)).await?;
15/// println!("status: {}", resp.status);
16/// println!("user: {:?}", resp.body);
17/// if let Some(etag) = resp.header("etag") {
18///     println!("etag: {etag:?}");
19/// }
20/// ```
21#[derive(Debug, Clone)]
22pub struct TypedResponse<T> {
23    /// The deserialized response body.
24    pub body: T,
25    /// The HTTP status code.
26    pub status: StatusCode,
27    /// The response headers.
28    pub headers: HeaderMap,
29}
30
31impl<T> TypedResponse<T> {
32    /// Get a specific header value by name.
33    pub fn header(&self, name: &str) -> Option<&HeaderValue> {
34        self.headers.get(name)
35    }
36}