Skip to content

Instantly share code, notes, and snippets.

@ravisorathiya
Last active July 3, 2023 08:38
Show Gist options
  • Save ravisorathiya/366675ed36f131413016dc06390ce411 to your computer and use it in GitHub Desktop.
Save ravisorathiya/366675ed36f131413016dc06390ce411 to your computer and use it in GitHub Desktop.
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