[Kotlin] [Feature] OkHttpClient - replacing static client usage with client Injection
Created by: tihonovgn
Is your feature request related to a problem? Please describe.
I need to use different interceptors for different api clients in a project. In the current implementation, I can only add an interceptor through the static field ApiClient.builder. In this case, all clients use the same interceptors.
@JvmStatic val builder: OkHttpClient.Builder = OkHttpClient.Builder()
Describe the solution you'd like
It would be nice to be able to inject your own instance of the OkHttpClient class into the API client constructor.
class V1Api(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = ApiClient.defaultClient) : ApiClient(basePath) {
fun getOrdersClient(): V3Api {
val builder = OkHttpClient.Builder()
builder.addInterceptor(
dbLoggerInterceptor
)
return V3Api(baseURL, builder.build())
}
fun getPickupsClient(): V3Api {
val builder = OkHttpClient.Builder()
builder.addInterceptor(
kibanaLoggerInterceptor
)
return V3Api(baseURL, builder.build())
}
@jimschubert @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m