Skip to content

Instantly share code, notes, and snippets.

@jesselima
Created May 15, 2020 14:20
Show Gist options
  • Save jesselima/4bf19efc6d7f76f383f755f7b23f37e0 to your computer and use it in GitHub Desktop.
Save jesselima/4bf19efc6d7f76f383f755f7b23f37e0 to your computer and use it in GitHub Desktop.
This is a Quick and easy way to use retrofit with koin.
private val apiModule = module {
// By default, Gson is strict and only accepts JSON as specified by RFC 4627 .
// This option makes the parser liberal in what it accepts
single { GsonBuilder().setLenient().create() }
single {
// val httpLoggingInterceptor = HttpLoggingInterceptor()
// httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.NONE
val okHttpClient = OkHttpClient()
.newBuilder()
//.addInterceptor(httpLoggingInterceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(get()))
.build()
retrofit.create(ApiServiceInterface::class.java)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment