Skip to main content

RestClient

Struct RestClient 

Source
pub struct RestClient { /* private fields */ }
Expand description

REST API client for Shopify Admin API.

Provides convenient methods (get, post, put, delete) for making REST API requests with automatic path normalization and retry handling.

§Thread Safety

RestClient is Send + Sync, making it safe to share across async tasks.

§Deprecation Notice

The Shopify Admin REST API is deprecated. A warning is logged when this client is constructed. Consider migrating to the GraphQL Admin API.

§Example

use shopify_sdk::{RestClient, Session, ShopDomain};

let session = Session::new(
    "session-id".to_string(),
    ShopDomain::new("my-store").unwrap(),
    "access-token".to_string(),
    "read_products".parse().unwrap(),
    false,
    None,
);

let client = RestClient::new(&session, None)?;

// GET request
let response = client.get("products", None).await?;

// POST request with body
let body = serde_json::json!({"product": {"title": "New Product"}});
let response = client.post("products", body, None).await?;

Implementations§

Source§

impl RestClient

Source

pub fn new( session: &Session, config: Option<&ShopifyConfig>, ) -> Result<Self, RestError>

Creates a new REST client for the given session.

This constructor uses the API version from the configuration, or falls back to the latest stable version if not specified.

§Arguments
  • session - The session providing shop domain and access token
  • config - Optional configuration for API version and other settings
§Errors

Returns RestError::RestApiDisabled if REST API is disabled in config (future-proofing for when REST is fully deprecated).

§Example
use shopify_sdk::{RestClient, Session, ShopDomain};

let session = Session::new(
    "session-id".to_string(),
    ShopDomain::new("my-store").unwrap(),
    "access-token".to_string(),
    "read_products".parse().unwrap(),
    false,
    None,
);

let client = RestClient::new(&session, None)?;
Source

pub fn with_version( session: &Session, config: Option<&ShopifyConfig>, version: ApiVersion, ) -> Result<Self, RestError>

Creates a new REST client with a specific API version override.

This constructor allows overriding the API version from configuration.

§Arguments
  • session - The session providing shop domain and access token
  • config - Optional configuration for other settings
  • version - The API version to use for requests
§Errors

Returns RestError::RestApiDisabled if REST API is disabled in config.

§Example
use shopify_sdk::{RestClient, Session, ShopDomain, ApiVersion};

let session = Session::new(
    "session-id".to_string(),
    ShopDomain::new("my-store").unwrap(),
    "access-token".to_string(),
    "read_products".parse().unwrap(),
    false,
    None,
);

// Use a specific API version
let client = RestClient::with_version(&session, None, ApiVersion::V2024_10)?;
Source

pub const fn api_version(&self) -> &ApiVersion

Returns the API version being used by this client.

Source

pub async fn get( &self, path: &str, query: Option<HashMap<String, String>>, ) -> Result<HttpResponse, RestError>

Sends a GET request to the specified path.

§Arguments
  • path - The REST API path (e.g., “products”, “orders/123”)
  • query - Optional query parameters
§Errors

Returns RestError::InvalidPath if the path is invalid (e.g., empty). Returns RestError::Http for HTTP-level errors.

§Example
// Simple GET
let response = client.get("products", None).await?;

// GET with query parameters
let mut query = HashMap::new();
query.insert("limit".to_string(), "50".to_string());
let response = client.get("products", Some(query)).await?;
Source

pub async fn get_with_tries( &self, path: &str, query: Option<HashMap<String, String>>, tries: u32, ) -> Result<HttpResponse, RestError>

Sends a GET request with retry configuration.

§Arguments
  • path - The REST API path
  • query - Optional query parameters
  • tries - Number of times to attempt the request (default: 1)
§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors, including retry exhaustion.

Source

pub async fn post( &self, path: &str, body: Value, query: Option<HashMap<String, String>>, ) -> Result<HttpResponse, RestError>

Sends a POST request to the specified path.

§Arguments
  • path - The REST API path (e.g., “products”)
  • body - The JSON body to send
  • query - Optional query parameters
§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors.

§Example
let body = serde_json::json!({
    "product": {
        "title": "New Product",
        "body_html": "<p>Description</p>"
    }
});
let response = client.post("products", body, None).await?;
Source

pub async fn post_with_tries( &self, path: &str, body: Value, query: Option<HashMap<String, String>>, tries: u32, ) -> Result<HttpResponse, RestError>

Sends a POST request with retry configuration.

§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors, including retry exhaustion.

Source

pub async fn put( &self, path: &str, body: Value, query: Option<HashMap<String, String>>, ) -> Result<HttpResponse, RestError>

Sends a PUT request to the specified path.

§Arguments
  • path - The REST API path (e.g., “products/123”)
  • body - The JSON body to send
  • query - Optional query parameters
§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors.

§Example
let body = serde_json::json!({
    "product": {
        "title": "Updated Title"
    }
});
let response = client.put("products/123", body, None).await?;
Source

pub async fn put_with_tries( &self, path: &str, body: Value, query: Option<HashMap<String, String>>, tries: u32, ) -> Result<HttpResponse, RestError>

Sends a PUT request with retry configuration.

§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors, including retry exhaustion.

Source

pub async fn delete( &self, path: &str, query: Option<HashMap<String, String>>, ) -> Result<HttpResponse, RestError>

Sends a DELETE request to the specified path.

§Arguments
  • path - The REST API path (e.g., “products/123”)
  • query - Optional query parameters
§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors.

§Example
let response = client.delete("products/123", None).await?;
Source

pub async fn delete_with_tries( &self, path: &str, query: Option<HashMap<String, String>>, tries: u32, ) -> Result<HttpResponse, RestError>

Sends a DELETE request with retry configuration.

§Errors

Returns RestError::InvalidPath if the path is invalid. Returns RestError::Http for HTTP-level errors, including retry exhaustion.

Trait Implementations§

Source§

impl Debug for RestClient

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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<T> Same for T

Source§

type Output = T

Should always be Self
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