arlyon / async-stripe

Async (and blocking!) Rust bindings for the Stripe API
https://payments.rs
Apache License 2.0
414 stars 121 forks source link

Idempotent request stratgey is per-client, not per-request #520

Open WesleyAC opened 3 months ago

WesleyAC commented 3 months ago

Is your feature request related to a problem? Please describe.

It's strange to me that the RequestStrategy is set on a per-client basis, rather than a per-request basis. If I'm interpreting this correctly, this means that the only way to make multiple idempotent requests with different keys is to create a new client for each request. Is this the correct way to use this library?

Describe the solution you'd like

A way to set the idempotency key per-request with the same client

Describe alternatives you've considered

Better documentation of this feature, in the case that creating a fresh client is low-cost and the correct way to do this.

Additional context

No response

arlyon commented 3 months ago

The client is cheap to clone so yes that is the intended strategy if you cannot use the exponential back off which handles the token for you per request. We are considering a new API for this in the impending rewrite (currently on the next branch) so that this is clearer since people (rightfully) get paranoid cloning things.

In the meantime time I will open a quick PR that explains this.