Skip to content

Instantly share code, notes, and snippets.

@iambaljeet
Created January 24, 2020 12:46
Show Gist options
  • Save iambaljeet/15de8f2b13715a427012ffea0ea69631 to your computer and use it in GitHub Desktop.
Save iambaljeet/15de8f2b13715a427012ffea0ea69631 to your computer and use it in GitHub Desktop.
object ApiProvider {
private val retrofit = Retrofit.Builder()
.baseUrl(ApiService.BASE_URL)
.client(getHttpClient())
.addConverterFactory(GsonConverterFactory.create())
.build()
private fun getHttpClient(): OkHttpClient {
val logging = HttpLoggingInterceptor()
logging.level = HttpLoggingInterceptor.Level.BODY
val httpClient = OkHttpClient.Builder()
httpClient.addInterceptor(logging)
return httpClient.build()
}
fun <S> createService(serviceClass: Class<S>?): S {
return retrofit.create(serviceClass)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment