Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Created October 28, 2020 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ikhiloya/ba98ea719525138e736181b5f4fdc136 to your computer and use it in GitHub Desktop.
Save Ikhiloya/ba98ea719525138e736181b5f4fdc136 to your computer and use it in GitHub Desktop.
Retrofit Instance for network calls in android
//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