1def retrofit_version = "2.9.0"
2implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
3implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
1public interface GitHubService {
2 @GET("users/{user}/repos")
3 Call<List<Repo>> listRepos(@Path("user") String user);
4}
1// Trailing slash is needed
2public static final String BASE_URL = "http://api.myservice.com/";
3Retrofit retrofit = new Retrofit.Builder()
4 .baseUrl(BASE_URL)
5 .addConverterFactory(GsonConverterFactory.create())
6 .build();
1RequestBody requestBody = new MultipartBody.Builder()
2 .setType(MultipartBody.FORM)
3 .addFormDataPart("title", "Square Logo")
4 .addFormDataPart("image", "logo-square.png",
5 RequestBody.create(MEDIA_TYPE_PNG, new File("website/static/logo-square.png")))
6 .build();