Created
November 19, 2018 11:58
-
-
Save clairtonluz/2c19a6a053b825df9401e026d23f775a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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