/retrofit2-kotlin-coroutines-adapter

A Retrofit 2 adapter for Kotlin coroutine's Deferred type.

Primary LanguageKotlinApache License 2.0Apache-2.0

Kotlin Coroutine (Experimental) Adapter

A Retrofit 2 CallAdapter.Factory for Kotlin coroutine's Deferred.

Usage

Add KotlinCoroutineCallAdapterFactory as a Call adapter when building your Retrofit instance:

val retrofit = Retrofit.Builder()
    .baseUrl("https://example.com/")
    .addCallAdapterFactory(KotlinCoroutineCallAdapter())
    .build()

Your service methods can now use Deferred as their return type.

interface MyService {
  @GET("/user")
  fun getUser(): Deferred<User>

  // or

  @GET("/user")
  fun getUser(): Deferred<Response<User>>
}

Download

Download the latest JAR or grab via Maven:

<dependency>
  <groupId>com.jakewharton.retrofit</groupId>
  <artifactId>retrofit2-kotlin-coroutines-experimental-adapter</artifactId>
  <version>1.0.0</version>
</dependency>

or Gradle:

compile 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2017 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.