Created
March 17, 2018 09:31
-
-
Save shakil807g/7e0679211bb8f50a19c63cc179082156 to your computer and use it in GitHub Desktop.
Network calls with kotlin coroutine + Android Architecture components
This file contains hidden or 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 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) | |
} | |
} |
This file contains hidden or 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
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