Created
October 28, 2020 06:58
-
-
Save Ikhiloya/ba98ea719525138e736181b5f4fdc136 to your computer and use it in GitHub Desktop.
Retrofit Instance for network calls in android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//OkHttpClient | |
val okHttpClient: OkHttpClient = OkHttpClient().newBuilder() | |
.cache(cache()) | |
.addInterceptor(httpLoggingInterceptor) | |
.addNetworkInterceptor(networkInterceptor) // only used when network is on | |
.addInterceptor(offlineCacheInterceptor) | |
.build() | |
//Retrofit | |
val retrofit: Retrofit = Retrofit.Builder() | |
.client(okHttpClient) | |
.baseUrl(BASE_URL) | |
.addConverterFactory(GsonConverterFactory.create(gson)) | |
.build() | |
paymentService = retrofit.create(PaymentService::class.java) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment