-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streaming requests #1207
Streaming requests #1207
Conversation
a953964
to
304aa7e
Compare
this.bodyStream = bodyStream; | ||
} | ||
|
||
public StripeResponse unstream() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding on this name encouraged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readStream
? readFromStream
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense overall - thanks for putting this together! My biggest feedback would be around the duplicated implementation for the response interface. Probably worth sharing that for now. Otherwise I think this all looks good!
public StripeResponse requestWithTelemetry(StripeRequest request) throws StripeException { | ||
public StripeResponseStream requestStream(StripeRequest request) throws StripeException { | ||
throw new UnsupportedOperationException( | ||
"streamingRequest is unimplemented for this HttpClient"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
streamingRequest -> requestStream?
this.bodyStream = bodyStream; | ||
} | ||
|
||
public StripeResponse unstream() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readStream
? readFromStream
?
import java.time.Instant; | ||
|
||
/** Common interface representing an HTTP response from Stripe. */ | ||
interface StripeResponseInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the majority of this implementation would be shared right (ie. all the header extraction)? If so, I think we could make some abstract class with the shared implementation to avoid duplicating the code and have both implementations extend this instead of (or along with) the interface. This might be nice for testing as well.
92c9ff3
to
9b16a15
Compare
5310d7e
to
001fdc0
Compare
001fdc0
to
6d2b0dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG! Just one naming nit!
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class StripeResponseStream extends AbstractStripeResponse<InputStream> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: StripeResponseStream -> StripeStreamResponse for consistency with other libraries?
Notify
r? @dcr-stripe
cc @stripe/api-libraries
Summary
Adds
ApiResource.requestStream
, which is likeApiResource.request
except does not buffer the response body into memory and makes no attempt to deserialize the body. Instead, returns anInputStream
.Motivation: a
/pdf
endpoint is coming soon to the Stripe API, which returns the bytes of a pdf. Users will want to e.g. pipe these bytes to a file, or pipe them to an email API. This is unlike all previous Stripe methods, which return JSON and are buffered into memory and parsed.Similar to https://github.com/stripe/stripe-node/pull/1157/files
I ran japi-compliance-checker and got the following
report -- no incompatible changes.