Skip to content

Instantly share code, notes, and snippets.

@clairtonluz
Created November 19, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clairtonluz/2c19a6a053b825df9401e026d23f775a to your computer and use it in GitHub Desktop.
Save clairtonluz/2c19a6a053b825df9401e026d23f775a to your computer and use it in GitHub Desktop.
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import org.junit.Test;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Path;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
public class RestFactoryTest {
@Test
public void teste() throws IOException {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com")
.addConverterFactory(GsonConverterFactory.create())
.client(new OkHttpClient.Builder().connectionSpecs(Collections.singletonList(ConnectionSpec.MODERN_TLS)).build())
.build();
GitHubService service = retrofit.create(GitHubService.class);
Response<Map<String, String>> execute = service.getUser("clairtonluz").execute();
Map<String, String> body = execute.body();
System.out.println(body);
}
private static interface GitHubService {
@GET("users/{username}")
Call<Map<String, String>> getUser(@Path("username") String username);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment