Skip to main content

ResourceResponse

Struct ResourceResponse 

Source
pub struct ResourceResponse<T> { /* private fields */ }
Expand description

A response from a REST resource operation.

This wrapper combines the resource data with metadata from the HTTP response, including pagination information and rate limit data.

The struct implements Deref<Target = T> for transparent access to the inner data. This allows calling methods on T directly through the response wrapper.

§Type Parameters

  • T - The type of data contained in the response. For single resources this is the resource type (e.g., Product). For collections, this is Vec<ResourceType> (e.g., Vec<Product>).

§Example

use shopify_sdk::rest::ResourceResponse;
use shopify_sdk::clients::{ApiCallLimit, PaginationInfo};

// Create a response with a vector of items
let response = ResourceResponse::new(
    vec!["item1", "item2", "item3"],
    Some(PaginationInfo {
        prev_page_info: None,
        next_page_info: Some("eyJsYXN0X2lkIjo0fQ".to_string()),
    }),
    Some(ApiCallLimit { request_count: 1, bucket_size: 40 }),
    Some("req-123".to_string()),
);

// Access items via Deref
assert_eq!(response.len(), 3);
assert_eq!(response[0], "item1");

// Access metadata
assert!(response.has_next_page());
assert!(!response.has_prev_page());

Implementations§

Source§

impl<T> ResourceResponse<T>

Source

pub const fn new( data: T, pagination: Option<PaginationInfo>, rate_limit: Option<ApiCallLimit>, request_id: Option<String>, ) -> Self

Creates a new ResourceResponse with the given data and metadata.

§Arguments
  • data - The resource data
  • pagination - Pagination info from Link header
  • rate_limit - Rate limit info from API call limit header
  • request_id - Request ID from X-Request-Id header
Source

pub fn into_inner(self) -> T

Consumes the response and returns the inner data.

Use this when you need ownership of the data and no longer need the response metadata.

§Example
use shopify_sdk::rest::ResourceResponse;

let response = ResourceResponse::new(
    vec![1, 2, 3],
    None,
    None,
    None,
);
let data: Vec<i32> = response.into_inner();
assert_eq!(data, vec![1, 2, 3]);
Source

pub const fn data(&self) -> &T

Returns a reference to the inner data.

Note: In most cases, you can use Deref coercion instead of calling this method explicitly.

Source

pub fn data_mut(&mut self) -> &mut T

Returns a mutable reference to the inner data.

Note: In most cases, you can use DerefMut coercion instead of calling this method explicitly.

Source

pub fn has_next_page(&self) -> bool

Returns true if there is a next page of results.

§Example
use shopify_sdk::rest::ResourceResponse;
use shopify_sdk::clients::PaginationInfo;

let response = ResourceResponse::new(
    vec!["item"],
    Some(PaginationInfo {
        prev_page_info: None,
        next_page_info: Some("token".to_string()),
    }),
    None,
    None,
);
assert!(response.has_next_page());
Source

pub fn has_prev_page(&self) -> bool

Returns true if there is a previous page of results.

Source

pub fn next_page_info(&self) -> Option<&str>

Returns the page info token for the next page, if available.

Use this token with the page_info query parameter to fetch the next page of results.

Source

pub fn prev_page_info(&self) -> Option<&str>

Returns the page info token for the previous page, if available.

Source

pub const fn pagination(&self) -> Option<&PaginationInfo>

Returns the pagination info, if available.

Source

pub const fn rate_limit(&self) -> Option<&ApiCallLimit>

Returns the rate limit information, if available.

§Example
use shopify_sdk::rest::ResourceResponse;
use shopify_sdk::clients::ApiCallLimit;

let response = ResourceResponse::new(
    "data",
    None,
    Some(ApiCallLimit { request_count: 5, bucket_size: 40 }),
    None,
);

let limit = response.rate_limit().unwrap();
assert_eq!(limit.request_count, 5);
assert_eq!(limit.bucket_size, 40);
Source

pub fn request_id(&self) -> Option<&str>

Returns the request ID from the response headers.

Useful for debugging and error reporting.

Source

pub fn map<U, F>(self, f: F) -> ResourceResponse<U>
where F: FnOnce(T) -> U,

Maps the inner data to a new type.

Useful for transforming the response data while preserving metadata.

Source§

impl<T: DeserializeOwned> ResourceResponse<T>

Source

pub fn from_http_response( response: HttpResponse, key: &str, ) -> Result<Self, ResourceError>

Creates a ResourceResponse from an HTTP response.

Extracts the data from the response body under the given key, along with pagination and rate limit information.

§Arguments
  • response - The HTTP response
  • key - The key in the response body containing the data
§Errors

Returns ResourceError::Http if the data cannot be deserialized.

§Example
use shopify_sdk::rest::ResourceResponse;

// Assuming response.body = {"product": {"id": 123, "title": "Test"}}
let response: ResourceResponse<Product> = ResourceResponse::from_http_response(
    http_response,
    "product",
)?;

Trait Implementations§

Source§

impl<T: Clone> Clone for ResourceResponse<T>

Source§

fn clone(&self) -> ResourceResponse<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for ResourceResponse<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for ResourceResponse<T>

Provides transparent access to the inner data.

This allows methods of T to be called directly on ResourceResponse<T>.

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for ResourceResponse<T>

Provides mutable access to the inner data.

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<T> Freeze for ResourceResponse<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ResourceResponse<T>
where T: RefUnwindSafe,

§

impl<T> Send for ResourceResponse<T>
where T: Send,

§

impl<T> Sync for ResourceResponse<T>
where T: Sync,

§

impl<T> Unpin for ResourceResponse<T>
where T: Unpin,

§

impl<T> UnwindSafe for ResourceResponse<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Formattable for T
where T: Deref, <T as Deref>::Target: Formattable,

Source§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,