Skip to content

shawnlinboy/retrofit-livedata-adapter

Repository files navigation

retrofit-livedata-adapter

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.

Download

implementation 'me.linshen.retrofit2:adapter-livedata:1.0.0'

Usage

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
                        }
                    }
                })

About

A library for adding LiveData support for Retrofit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages