wyyerd / stripe-rs

Rust API bindings for the Stripe HTTP API.
Apache License 2.0
223 stars 88 forks source link

Support for idempotent requests. #129

Open thedodd opened 4 years ago

thedodd commented 4 years ago

Per the docs here https://stripe.com/docs/api/idempotent_requests, it would be quite nice if the various API interaction methods supported a way to set this header. There are a few different ways this value could be set. Method param. Constructor pattern for the requests. We should be able to find a solid path forward.

Hard requirements:

kestred commented 4 years ago

Up to this point the library has used the Headers struct to represent similar patterns (e.g. Stripe-Account)

Also see the comment I added #130.

erichCompSci commented 2 years ago

Hi, in a downstream repo (the async stripe) I've provided an implementation for this by forcing all post requests to take an optional value. That way you can determine if you want this particular header or not per request. This is a significant API change, and it does require changing the generation code.

I know this is a wanted feature. I can not actively support both the non-async code and the async code, but I am willing to discuss this and figure out a common interface and make the changes as necessary.

The biggest problem with adding this to the header struct is that it kind of forces this to be decided per Stripe connection, which means one Stripe connection per API request for different Idempotency calls. That is...a bad idea in my humble opinion.

Adding on an optional idempotency request is another way to go about it, but requires a lot of changes. Alternatively, we could add a new method to all post requests that had an Idempotent string. So instead of just create and update you would have create, create_with_idempotent_key and update and update_with_idempotent_key. That would be backward compatible.

I should also note that we made some changes to the downstream code generation, so if you haven't absorbed them, I can only get you halfway there with the changes. Mostly just looking for the conversation around this feature so that we could start discussing this feature in earnest. I am using this feature right now and will support.