-
Notifications
You must be signed in to change notification settings - Fork 16
feat: cleaning up http client interface and adding the ability to use custom http clients #237
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
Conversation
core/src/main/java/com/amplitude/core/platform/EventPipeline.kt
Outdated
Show resolved
Hide resolved
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.
lgtm
# [1.20.0](v1.19.4...v1.20.0) (2025-02-11) ### Features * cleaning up http client interface and adding the ability to use custom http clients ([#237](#237)) ([bddd9d7](bddd9d7))
🎉 This PR is included in version 1.20.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
val ampRequest = AnalyticsRequest(apiKey, events, diagnostics = diagnostics) | ||
val formBody: RequestBody = RequestBody.create(mediaType, ampRequest.getBodyStr()) | ||
val request: Request = | ||
Request.Builder().url("https://api.amplitude.com/2/httpapi").post(formBody).build() |
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.
How are customers supposed to implement a custom API client properly without having access to getServerUrl()
or minIdLength
from the internal configuration? Hardcoding these values is definitely not a good option.
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.
The initial plan was to make our http client an open class which can be extended. But we were running into a circular dependency.
The http client needs a configuration to be initialized and the custom http client needed to be passed into the configuration so that the Amplitude client can be configured to use a custom http client.
Since the HttpClient is an interface, you can define your class that takes in the Amplitude configuration to fetch all the properties from the configuration directly.
For example
class CustomClient() : HttpClientInterface {
fun initialize(configuration: Configuration) {
....
}
// override upload here
}
And in init
val customClient = CustomClient()
val config = Configuration(...)
customClient.initialize(config)
val amplitude = Amplitude(configuration)
I can update the example to show this and also open to suggestions.
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.
Something like this: #240
Summary
Checklist