Questions tagged [retrofit2]

Retrofit2 is the second version of the type-safe REST client Retrofit for Android and Java. It is developed by Square, Inc.

To use it with Maven:

<dependency>
  <groupId>com.squareup.retrofit2</groupId>
  <artifactId>retrofit</artifactId>
  <version>2.3.0</version>
</dependency>

Or with Gradle:

compile 'com.squareup.retrofit2:retrofit:2.X.X'

It requires minimum Android 2.3 (Gingerbread) and Java 7 to use it.

If you are using ProGuard add following options:

# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain service method parameters.
-keepclassmembernames,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

How to use it:

Retrofit turns your HTTP API into a Java interface.

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

This Retrofit class generates an implementation of the GitHubService interface.

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .build();

GitHubService service = retrofit.create(GitHubService.class);

Each call from the created GitHubService can make a synchronous or asynchronous HTTP request to the remote web server.

Call<List<Repo>> repos = service.listRepos("octocat");

Use annotations to describe the HTTP request:

  • URL parameter replacement and query parameter support
  • Object conversion to request body (e.g., JSON, protocol buffers)
  • Multipart request body and file upload
7553 questions
2
votes
1 answer

No content to map due to end-of-input when using Retrofit

I'm trying to use Retrofit to make a GET request to the following URL https://fantasy.premierleague.com/drf/leagues-classic-standings/670123 It seems to be failing to convert the JSON to an Object My retrofit builder looks like this Retrofit build…
JaAnTr
  • 896
  • 3
  • 16
  • 28
2
votes
1 answer

java.lang.IllegalArgumentException: 'retrofit2.Response' is not a valid response body type. Did you mean ResponseBody? for method Api.NewLocation

I am trying to set dummy data to be sent using my API but unfortunately, I cannot define the error in my logCat. Call call=RetrofitClient .getmInstance() .getApi() …
user6440030
2
votes
1 answer

File is empty after creating it using Uri - Retrofit

I'm trying to create a file using Uri. But when it is checked whether its empty, it is found empty. Below is the code where the Uri is stored in the variable "filePath". @Override protected void onActivityResult(int requestCode, int…
Lano Angel
  • 299
  • 5
  • 18
2
votes
0 answers

How to serialize and handle dynamic JSON keys?

I have to deal with an API with many nested dynamic JSON keys with a lot of nesting. My Json Response is like that: { "success": true, "data": { "infoArr": { "868.111": { "COURSE_ID": "868.111", "COURSE_NAME_PL":…
Ali Habbash
  • 777
  • 2
  • 6
  • 29
2
votes
0 answers

Retrofit handle Flux return type

How to hanle Flux return type in retrofit? EndPointApi public interface DataEndPointApi { @GET( "ap1/v3/data") Flux getAllData(@Query( "dataType") String dataType); } RetroRestAdapter @Autowired private ObjectMapper…
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
2
votes
3 answers

Retrofit is not able to find the host

I was following a tutorial on this link http://thetechnocafe.com/getting-started-with-retrofit-in-android/ to refresh my knowledge on how to use retrofit. But when I get the response, it calls onFailure with the following error Unable to resolve…
Armando Sudi
  • 137
  • 1
  • 12
2
votes
1 answer

Use cached response only. Without network call

There is an API that has calls limit, in this case I want to cache response and don't run network response if cache is still valid. First of all I have cache interceptor fun provideCacheInterceptor(): Interceptor = Interceptor { chain -> val…
dilix
  • 3,761
  • 3
  • 31
  • 55
2
votes
1 answer

Using Retrofit 2 For getting and fetching Unknown set of data

Retrofit is a wonderful library, it is simple to use and maintain, but My case is different, as we know, we should apply the stages of creating a retrofit api and response accordingly, retrofit instance: retrofit = new Retrofit.Builder() …
KhalodaRK84
  • 85
  • 2
  • 14
2
votes
2 answers

Unexpected JDWP Error: 103. Exception during Retrofit(2.3.0) GET call

I am getting Unexpected JDWP Error: 103 during call to vk.api to fetch some data. I have found this topic with related problem, but suggestion from there is already applyed in my application. So maybe my retrofit configuration is wrong? Here some…
Andrew
  • 591
  • 2
  • 12
  • 33
2
votes
2 answers

Issue in getting json response data using Retrofit

I am using Retrofit and having some issue in getting the data from response for the inner class. DEPENDENCES: //// retrofit, gson implementation 'com.google.code.gson:gson:2.6.2' implementation 'com.squareup.retrofit2:retrofit:2.4.0' implementation…
Jaimin Modi
  • 1,530
  • 4
  • 20
  • 72
2
votes
1 answer

I can re-call using retrofit 2

Can I re-call when there is no internet in mobile in onFailure? Code: private void ShowData() { rv_categories.setVisibility(View.GONE); txt_loading.setVisibility(View.VISIBLE); Loading(); Retrofit retrofit = new…
Taha Sami
  • 1,565
  • 1
  • 16
  • 43
2
votes
1 answer

Adding a query to a URL that already has a question mark with Retrofit

By good design, Retrofit will add your query to your URL as an ampersand rather than a question mark if there's already a question mark in the URL. However, I have no control over the URL and so am unable to change it. Is there a way that I can…
Josh Laird
  • 6,974
  • 7
  • 38
  • 69
2
votes
2 answers

How to send an array of images along with data per image using Retrofit 2?

Let's say I have this model: data class PhotoRequest( @SerializedName("page_number") val pageNumber: Int, @SerializedName("image") val requestBody: MultipartBody.Part ) The multipart is created using this: val photo = File(picturePath) val…
Gabriel Aguirre
  • 589
  • 4
  • 9
2
votes
0 answers

Android. SSLHandshakeException Connection reset by peer in AsyncHttpClient or Retrofit

Does someone know what can be wrong in configuration, that I getting such exception: javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x71c528b200: I/O error during system call, Connection reset by peer And how to configure this…
D.K.
  • 1,315
  • 2
  • 11
  • 20
2
votes
1 answer

how to view result of php script on android text view

I want to get the result of a PHP script to display on Android Textview using retrofit I was able to send data in an edit text to the database doing something like this This is for the post method InstituteService instituteService =…
1 2 3
99
100