Last active
July 3, 2023 08:38
-
-
Save ravisorathiya/366675ed36f131413016dc06390ce411 to your computer and use it in GitHub Desktop.
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
object MyApi { | |
private const val BASE_URL = " https://www.MYAPI.com/" | |
private val moshi = Moshi.Builder() | |
.add(KotlinJsonAdapterFactory()) | |
.build() | |
private val retrofit = Retrofit.Builder() | |
.addConverterFactory(MoshiConverterFactory.create(moshi)) | |
.addCallAdapterFactory(CoroutineCallAdapterFactory()) | |
.client(clientBuilder.build()) | |
.baseUrl(BASE_URL) | |
.build() | |
val retrofitService: MyApiService by lazy { | |
retrofit().create(MyApiService::class.java) | |
} | |
//If you want more service just add more val such as | |
val otherService: MyOtherService by lazy { | |
retrofit().create(MyOtherService::class.java | |
} | |
} | |
//To use it you just need to do: | |
MyApi.retrofitService | |
MyApi.otherService |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment