Skip to main content

RestResource

Trait RestResource 

Source
pub trait RestResource:
    Serialize
    + DeserializeOwned
    + Clone
    + Send
    + Sync
    + Sized {
    type Id: Display + Clone + Send + Sync;
    type FindParams: Serialize + Default + Send + Sync;
    type AllParams: Serialize + Default + Send + Sync;
    type CountParams: Serialize + Default + Send + Sync;

    const NAME: &'static str;
    const PLURAL: &'static str;
    const PATHS: &'static [ResourcePath];
    const PREFIX: Option<&'static str> = None;

    // Required method
    fn get_id(&self) -> Option<Self::Id>;

    // Provided methods
    fn resource_key() -> String { ... }
    async fn find(
        client: &RestClient,
        id: Self::Id,
        params: Option<Self::FindParams>,
    ) -> Result<ResourceResponse<Self>, ResourceError> { ... }
    async fn all(
        client: &RestClient,
        params: Option<Self::AllParams>,
    ) -> Result<ResourceResponse<Vec<Self>>, ResourceError> { ... }
    async fn all_with_parent<ParentId: Display + Send>(
        client: &RestClient,
        parent_id_name: &str,
        parent_id: ParentId,
        params: Option<Self::AllParams>,
    ) -> Result<ResourceResponse<Vec<Self>>, ResourceError> { ... }
    async fn save(&self, client: &RestClient) -> Result<Self, ResourceError> { ... }
    async fn save_partial(
        &self,
        client: &RestClient,
        changed_fields: Value,
    ) -> Result<Self, ResourceError> { ... }
    async fn delete(&self, client: &RestClient) -> Result<(), ResourceError> { ... }
    async fn count(
        client: &RestClient,
        params: Option<Self::CountParams>,
    ) -> Result<u64, ResourceError> { ... }
    fn build_full_path(path: &str) -> String { ... }
}
Expand description

A REST resource that can be fetched, created, updated, and deleted.

This trait provides a standardized interface for CRUD operations on Shopify REST API resources. Implementors define the resource’s paths, name, and parameter types, and get default implementations for all CRUD methods.

§Associated Types

  • Id: The type of the resource’s identifier (usually u64 or String)
  • FindParams: Parameters for find() operations (use () if none)
  • AllParams: Parameters for all() operations (pagination, filters, etc.)
  • CountParams: Parameters for count() operations

§Associated Constants

  • NAME: The singular resource name (e.g., “Product”)
  • PLURAL: The plural form used in URLs (e.g., “products”)
  • PATHS: Available paths for different operations
  • PREFIX: Optional path prefix for nested resources

§Required Bounds

Resources must be serializable, deserializable, cloneable, and thread-safe.

Required Associated Constants§

Source

const NAME: &'static str

The singular name of the resource (e.g., “Product”).

Used in error messages and as the response body key for single resources.

Source

const PLURAL: &'static str

The plural name used in URL paths (e.g., “products”).

Used as the response body key for collection operations.

Source

const PATHS: &'static [ResourcePath]

Available paths for this resource.

Define paths for each operation the resource supports. The path selection logic will choose the most specific path that matches the available IDs.

Provided Associated Constants§

Source

const PREFIX: Option<&'static str> = None

Optional path prefix for nested resources.

Override this for resources that always appear under a parent path.

Required Associated Types§

Source

type Id: Display + Clone + Send + Sync

The type of the resource’s identifier.

Source

type FindParams: Serialize + Default + Send + Sync

Parameters for find() operations.

Use () if no parameters are needed.

Source

type AllParams: Serialize + Default + Send + Sync

Parameters for all() operations (filtering, pagination, etc.).

Use () if no parameters are needed.

Source

type CountParams: Serialize + Default + Send + Sync

Parameters for count() operations.

Use () if no parameters are needed.

Required Methods§

Source

fn get_id(&self) -> Option<Self::Id>

Returns the resource’s ID if it exists.

Returns None for new resources that haven’t been saved yet.

Provided Methods§

Source

fn resource_key() -> String

Returns the lowercase key used in JSON request/response bodies.

Source

async fn find( client: &RestClient, id: Self::Id, params: Option<Self::FindParams>, ) -> Result<ResourceResponse<Self>, ResourceError>

Finds a single resource by ID.

§Arguments
  • client - The REST client to use for the request
  • id - The resource ID to find
  • params - Optional parameters for the request
§Errors

Returns ResourceError::NotFound if the resource doesn’t exist. Returns ResourceError::PathResolutionFailed if no valid path matches.

§Example
let product = Product::find(&client, 123, None).await?;
println!("Found: {}", product.title);
Source

async fn all( client: &RestClient, params: Option<Self::AllParams>, ) -> Result<ResourceResponse<Vec<Self>>, ResourceError>

Lists all resources matching the given parameters.

Returns a paginated response. Use has_next_page() and next_page_info() to navigate through pages.

§Arguments
  • client - The REST client to use for the request
  • params - Optional parameters for filtering/pagination
§Errors

Returns ResourceError::PathResolutionFailed if no valid path matches.

§Example
let response = Product::all(&client, None).await?;
for product in response.iter() {
    println!("Product: {}", product.title);
}

if response.has_next_page() {
    // Fetch next page...
}
Source

async fn all_with_parent<ParentId: Display + Send>( client: &RestClient, parent_id_name: &str, parent_id: ParentId, params: Option<Self::AllParams>, ) -> Result<ResourceResponse<Vec<Self>>, ResourceError>

Lists resources with a specific parent resource ID.

For nested resources that require a parent ID (e.g., variants under products).

§Arguments
  • client - The REST client to use
  • parent_id_name - The name of the parent ID parameter (e.g., product_id)
  • parent_id - The parent resource ID
  • params - Optional parameters for filtering/pagination
§Errors

Returns ResourceError::PathResolutionFailed if no valid path matches.

Source

async fn save(&self, client: &RestClient) -> Result<Self, ResourceError>

Saves the resource (create or update).

For new resources (no ID), sends a POST request to create. For existing resources (has ID), sends a PUT request to update.

When updating, only changed fields are sent if dirty tracking is used.

§Arguments
  • client - The REST client to use
§Returns

The saved resource with any server-generated fields populated.

§Errors

Returns ResourceError::ValidationFailed if validation fails (422). Returns ResourceError::NotFound if updating a non-existent resource.

§Example
// Create new
let mut product = Product { id: None, title: "New".to_string(), vendor: None };
let saved = product.save(&client).await?;

// Update existing
let mut product = Product::find(&client, 123, None).await?.into_inner();
product.title = "Updated".to_string();
let saved = product.save(&client).await?;
Source

async fn save_partial( &self, client: &RestClient, changed_fields: Value, ) -> Result<Self, ResourceError>

Saves the resource with dirty tracking for partial updates.

For existing resources, only sends changed fields in the PUT request. This is more efficient than save() for large resources.

§Arguments
  • client - The REST client to use
  • changed_fields - JSON value containing only the changed fields
§Returns

The saved resource with server-generated fields populated.

Source

async fn delete(&self, client: &RestClient) -> Result<(), ResourceError>

Deletes the resource.

§Arguments
  • client - The REST client to use
§Errors

Returns ResourceError::NotFound if the resource doesn’t exist. Returns ResourceError::PathResolutionFailed if no delete path exists.

§Example
let product = Product::find(&client, 123, None).await?;
product.delete(&client).await?;
Source

async fn count( client: &RestClient, params: Option<Self::CountParams>, ) -> Result<u64, ResourceError>

Counts resources matching the given parameters.

§Arguments
  • client - The REST client to use
  • params - Optional parameters for filtering
§Returns

The count of matching resources as a u64.

§Errors

Returns ResourceError::PathResolutionFailed if no count path exists.

§Example
let count = Product::count(&client, None).await?;
println!("Total products: {}", count);
Source

fn build_full_path(path: &str) -> String

Builds the full path including any prefix.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::AccessScope

Source§

const NAME: &'static str = "AccessScope"

Source§

const PLURAL: &'static str = "access_scopes"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::AccessScope

Source§

const NAME: &'static str = "AccessScope"

Source§

const PLURAL: &'static str = "access_scopes"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::ApplicationCharge

Source§

const NAME: &'static str = "ApplicationCharge"

Source§

const PLURAL: &'static str = "application_charges"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ApplicationChargeFindParams

Source§

type AllParams = ApplicationChargeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::ApplicationCharge

Source§

const NAME: &'static str = "ApplicationCharge"

Source§

const PLURAL: &'static str = "application_charges"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ApplicationChargeFindParams

Source§

type AllParams = ApplicationChargeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Article

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Article

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Blog

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Blog

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Collect

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Collect

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Comment

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Comment

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Country

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Country

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Currency

Source§

const NAME: &'static str = "Currency"

Source§

const PLURAL: &'static str = "currencies"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Currency

Source§

const NAME: &'static str = "Currency"

Source§

const PLURAL: &'static str = "currencies"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::CustomCollection

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::CustomCollection

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Customer

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Customer

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::DiscountCodeResource

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::DiscountCodeResource

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::DraftOrder

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::DraftOrder

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Event

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Event

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Fulfillment

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Fulfillment

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::FulfillmentOrder

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::FulfillmentOrder

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::FulfillmentService

Source§

const NAME: &'static str = "FulfillmentService"

Source§

const PLURAL: &'static str = "fulfillment_services"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = FulfillmentServiceFindParams

Source§

type AllParams = FulfillmentServiceListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::FulfillmentService

Source§

const NAME: &'static str = "FulfillmentService"

Source§

const PLURAL: &'static str = "fulfillment_services"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = FulfillmentServiceFindParams

Source§

type AllParams = FulfillmentServiceListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::GiftCard

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::GiftCard

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::InventoryItem

Source§

const NAME: &'static str = "InventoryItem"

Source§

const PLURAL: &'static str = "inventory_items"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = InventoryItemFindParams

Source§

type AllParams = InventoryItemListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::InventoryItem

Source§

const NAME: &'static str = "InventoryItem"

Source§

const PLURAL: &'static str = "inventory_items"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = InventoryItemFindParams

Source§

type AllParams = InventoryItemListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::InventoryLevel

Source§

const NAME: &'static str = "InventoryLevel"

Source§

const PLURAL: &'static str = "inventory_levels"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = InventoryLevelListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::InventoryLevel

Source§

const NAME: &'static str = "InventoryLevel"

Source§

const PLURAL: &'static str = "inventory_levels"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = InventoryLevelListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Location

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Location

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Metafield

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Metafield

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Order

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Order

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Page

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Page

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Policy

Source§

const NAME: &'static str = "Policy"

Source§

const PLURAL: &'static str = "policies"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Policy

Source§

const NAME: &'static str = "Policy"

Source§

const PLURAL: &'static str = "policies"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = String

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::PriceRule

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::PriceRule

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Product

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Product

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::ProductImageResource

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::ProductImageResource

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Province

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Province

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::RecurringApplicationCharge

Source§

const NAME: &'static str = "RecurringApplicationCharge"

Source§

const PLURAL: &'static str = "recurring_application_charges"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = RecurringApplicationChargeFindParams

Source§

type AllParams = RecurringApplicationChargeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::RecurringApplicationCharge

Source§

const NAME: &'static str = "RecurringApplicationCharge"

Source§

const PLURAL: &'static str = "recurring_application_charges"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = RecurringApplicationChargeFindParams

Source§

type AllParams = RecurringApplicationChargeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Redirect

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Redirect

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::RefundResource

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::RefundResource

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::ScriptTag

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::ScriptTag

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Shop

Source§

const NAME: &'static str = "Shop"

Source§

const PLURAL: &'static str = "shop"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Shop

Source§

const NAME: &'static str = "Shop"

Source§

const PLURAL: &'static str = "shop"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::SmartCollection

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::SmartCollection

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::StorefrontAccessToken

Source§

const NAME: &'static str = "StorefrontAccessToken"

Source§

const PLURAL: &'static str = "storefront_access_tokens"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::StorefrontAccessToken

Source§

const NAME: &'static str = "StorefrontAccessToken"

Source§

const PLURAL: &'static str = "storefront_access_tokens"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ()

Source§

type AllParams = ()

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Theme

Source§

const NAME: &'static str = "Theme"

Source§

const PLURAL: &'static str = "themes"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ThemeFindParams

Source§

type AllParams = ThemeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Theme

Source§

const NAME: &'static str = "Theme"

Source§

const PLURAL: &'static str = "themes"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = ThemeFindParams

Source§

type AllParams = ThemeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Transaction

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Transaction

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::UsageCharge

Source§

const NAME: &'static str = "UsageCharge"

Source§

const PLURAL: &'static str = "usage_charges"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = UsageChargeFindParams

Source§

type AllParams = UsageChargeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::UsageCharge

Source§

const NAME: &'static str = "UsageCharge"

Source§

const PLURAL: &'static str = "usage_charges"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = UsageChargeFindParams

Source§

type AllParams = UsageChargeListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::User

Source§

const NAME: &'static str = "User"

Source§

const PLURAL: &'static str = "users"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = UserFindParams

Source§

type AllParams = UserListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::User

Source§

const NAME: &'static str = "User"

Source§

const PLURAL: &'static str = "users"

Source§

const PATHS: &'static [ResourcePath]

Source§

type Id = u64

Source§

type FindParams = UserFindParams

Source§

type AllParams = UserListParams

Source§

type CountParams = ()

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Variant

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Variant

Source§

impl RestResource for shopify_sdk::rest::resources::v2025_10::Webhook

Source§

impl RestResource for shopify_sdk::rest::resources::v2026_04::Webhook