Skip to content

Instantly share code, notes, and snippets.

@shakil807g
Created March 17, 2018 09:31
Show Gist options
  • Save shakil807g/7e0679211bb8f50a19c63cc179082156 to your computer and use it in GitHub Desktop.
Save shakil807g/7e0679211bb8f50a19c63cc179082156 to your computer and use it in GitHub Desktop.
Network calls with kotlin coroutine + Android Architecture components
object ApiClient {
fun getIntance(): ApiStores {
val builder = OkHttpClient.Builder()
if (BuildConfig.DEBUG) {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
builder.addInterceptor(loggingInterceptor)
}
val okHttpClient = builder.build()
val retrofit = Retrofit.Builder()
.baseUrl(ApiStores.API_SERVER_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(retrofit2.converter.gson.GsonConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.client(okHttpClient)
.build()
return retrofit.create(ApiStores::class.java)
}
}
interface ApiStores {
companion object {
const val API_SERVER_URL = "somebaseurl"
}
@GET("group/listSchools")
fun listSchool(@Header("Authorization") token: String): Deferred<Wrapper<List<School?>?>>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment