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
impl RestClient
Sourcepub fn new(
session: &Session,
config: Option<&ShopifyConfig>,
) -> Result<Self, RestError>
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 tokenconfig- 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)?;Sourcepub fn with_version(
session: &Session,
config: Option<&ShopifyConfig>,
version: ApiVersion,
) -> Result<Self, RestError>
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 tokenconfig- Optional configuration for other settingsversion- 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)?;Sourcepub const fn api_version(&self) -> &ApiVersion
pub const fn api_version(&self) -> &ApiVersion
Returns the API version being used by this client.
Sourcepub async fn get(
&self,
path: &str,
query: Option<HashMap<String, String>>,
) -> Result<HttpResponse, RestError>
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?;Sourcepub async fn get_with_tries(
&self,
path: &str,
query: Option<HashMap<String, String>>,
tries: u32,
) -> Result<HttpResponse, RestError>
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 pathquery- Optional query parameterstries- 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.
Sourcepub async fn post(
&self,
path: &str,
body: Value,
query: Option<HashMap<String, String>>,
) -> Result<HttpResponse, RestError>
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 sendquery- 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?;Sourcepub async fn post_with_tries(
&self,
path: &str,
body: Value,
query: Option<HashMap<String, String>>,
tries: u32,
) -> Result<HttpResponse, RestError>
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.
Sourcepub async fn put(
&self,
path: &str,
body: Value,
query: Option<HashMap<String, String>>,
) -> Result<HttpResponse, RestError>
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 sendquery- 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?;Sourcepub async fn put_with_tries(
&self,
path: &str,
body: Value,
query: Option<HashMap<String, String>>,
tries: u32,
) -> Result<HttpResponse, RestError>
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.
Sourcepub async fn delete(
&self,
path: &str,
query: Option<HashMap<String, String>>,
) -> Result<HttpResponse, RestError>
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?;Sourcepub async fn delete_with_tries(
&self,
path: &str,
query: Option<HashMap<String, String>>,
tries: u32,
) -> Result<HttpResponse, RestError>
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.