Skip to content

Ability to assign a default value to $maxTries in REST requests #281

@ugurarici

Description

@ugurarici

Overview

I would like to request the ability to assign a default value to the $maxTries parameter in REST requests.

Type

  • New feature
  • Changes to existing features

Motivation

What inspired this feature request? What problems were you facing?

Currently, when using "Rest resources" to make requests, for example, when calling the save() method on a PHP object derived from the Shopify\Rest\Admin2023_04\Customer class, a default Shopify\Clients\Rest object is created here. Depending on the desired operation and the corresponding HTTP method required, one of the get(), post(), put(), or delete() methods is invoked on this object. Although these methods can accept a $tries parameter, if this parameter is not explicitly provided when calling the relevant method, it is assumed to be null, and a default $maxTries value of 1 is assigned. When we create an object from a "Rest resource" class like Shopify\Rest\Admin2023_04\Customer, we do not directly invoke the get(), post(), put(), or delete() methods ourselves, as the class internally handles this. Therefore, we are unable to pass the $tries parameter ourselves. Consequently, when using "Rest resources," we cannot achieve multiple retries for an operation. If we can assign a default $tries value at some point during the package initialization, for example when setting up the library with Shopify\Context::initialize method, unless we override it, we can ensure that the operation is retried at least that many times.

So we can initialize the Context with something like this:

Context::initialize(
    apiKey: $_ENV['SHOPIFY_API_KEY'],
    apiSecretKey: $_ENV['SHOPIFY_API_SECRET'],
    scopes: $_ENV['SHOPIFY_APP_SCOPES'],
    hostName: $_ENV['SHOPIFY_APP_HOST_NAME'],
    sessionStorage: new FileSessionStorage('/tmp/php_sessions'),
    apiVersion: '2023-04',
    maxTries: 5,
    isEmbeddedApp: true,
    isPrivateApp: false,
);

And request method of Shopify\Clients\Http can use this as default value.

$maxTries = $tries ?? Context::$MAX_TRIES;

instead of

$maxTries = $tries ?? 1;

Area

  • Add any relevant Area: <area> labels to this issue

Checklist

  • I have described this feature request in a way that is actionable (if possible)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions