This library mostly mirrors code from googlesamples/android-architecture-components, which can add LiveData support for Retrofit.
In a sense, this can be viewed as an official support.
implementation 'me.linshen.retrofit2:adapter-livedata:1.0.0'
Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(LiveDataCallAdapterFactory())
.build()
.create(GithubService::class.java)
.getUser("shawnlinboy").observe(this,
Observer { response ->
when (response) {
is ApiSuccessResponse -> {
//success response
}
else -> {
//failed response
}
}
})