Created
May 15, 2020 14:20
-
-
Save jesselima/4bf19efc6d7f76f383f755f7b23f37e0 to your computer and use it in GitHub Desktop.
This is a Quick and easy way to use retrofit with koin.
This file contains 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
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