Retrofit 2 Synchronous Adapter

Additional

Language
Java
Version
N/A
Created
Mar 5, 2017
Updated
Aug 29, 2017
Owner
Jared Burrows (jaredsburrows)
Contributor
Jared Burrows (jaredsburrows)
1
Activity
Badge
Generate
Download
Source code

Commercial

Retrofit 2 Synchronous Adapter

A synchronous CallAdapter.Factory implementation for Retrofit 2.

This project brings Retrofit 1's synchronous usage to Retrofit 2.

Usage

// Setup retrofit
Retrofit retrofit = new Retrofit.Builder()
  .baseUrl("https://api.example.com")
  .addCallAdapterFactory(SynchronousCallAdapterFactory.create())
  .build();

// Create your service
interface Service {
  @GET("/") ApiResponse response();                 // Return type directly
  @GET("/") Response<ApiResponse> responseApi();    // Return Response information with type
  @GET("/") ResponseBody body();                    // Return generic type directly
  @GET("/") Response<ResponseBody> responseBody();  // Return Response information with generic type
}

// Initiate the service
Service example = retrofit.create(Service.class);

// Make your HTTP request
ApiResponse response = example.response();
ResponseBody body = example.body();
Response<ResponseBody> responseBody = example.responseBody();
Response<ApiResponse> responseApi = example.responseApi();

Download

Gradle:

repositories {
  jcenter()
}
  
compile "com.jaredsburrows.retrofit:retrofit2-synchronous-adapter:0.4.0"

Snapshot versions are available in the JFrog Artifactory repository: https://oss.jfrog.org/webapp/#/builds/retrofit2-synchronous-adapter