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

How to resolve the error of getting response 400 while signup through api in android retrofit 2

When I used to click on submit button by filing all the details I am getting response 400. So can you Please help me to get out of it. Below There is my Postman. I'm using the library retrofit 2.5.0 My POJO Class public class Signup…
2
votes
1 answer

Problems on call retrofit

I newbie on kotlin, its my firts app test. I trying to do a retrofit call (POST) but i get sintax error on create code. My syntax error: no type arguments expected for CallBack this is my doLogin function on presenter layer (i got error…
Flávio Costa
  • 895
  • 5
  • 18
  • 41
2
votes
1 answer

RxJava2 question: How Zip handles error when calling multiple services in parallel?

Suppose we have 3 services, employeeTitle, employeeName, employeeLocation. If all services three services throw error employeeTitle, employeeName and employeeLocation will service only throw 1 error? According to the documentation this should be…
2
votes
3 answers

How get JSON as string using retrofit

Please i'm new to retrofit and I've been stuck for weeks now, i tried getting my response as POJO class and end up with this error "Json document was not fully consumed", I've searched and also ask this question here and no one was able to help get…
Eidris
  • 117
  • 2
  • 10
2
votes
0 answers

getting json exception with Retrofit version 2.0 and special character "-" and "_" in email address

I'm having trouble passing in any email address with the character - or a _ when a user tries to sign up. Here is the retrofit definition: @Headers(API_KEY) @FormUrlEncoded @POST("signInUser") Call signInUser(@Field(value…
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
2
votes
2 answers

How can i create a retrofit api method call that doesnt return a response

I am trying to create an api call that doesn't have a response with retrofit, but the call does not return any thing, so how do i handle it in Retrofit i have a code like this : @POST("/message") public Call
Oto-obong Eshiett
  • 1,459
  • 3
  • 18
  • 33
2
votes
3 answers

how to Post data in an array in android using retrofit 2

i am facing a problem regarding posting data in an array in android using retrofit 2. i have to post the data of nearly 14 fields in my profile setting activity ... Like this ... name="basics[first_name] , name="basics[last_name]" ,…
S.H
  • 139
  • 13
2
votes
3 answers

JSON Data is not retrieved serially to RecyclerView

When First open my app, it showing 1-5 or 7 is serially. then, i scroll my Recyclerview it shows the item randomly. this is the main json link : http://services.hanselandpetal.com/feeds/flowers.json see image for more details when first open when…
2
votes
1 answer

How to use a specific query in Retrofit with Android?

I have an API interface which has two overloaded methods: public interface Api { @GET("movie/now_playing") Call getMovies(@Query("page") int page); @GET("search/movie") Call getMovies(@Query("query") String…
2
votes
0 answers

Android - API response returns OK but list is empty

I am using Google Books API to display relevant informations about books (like title, authors, publisher...) in a recyclerview and to do that I am using Retrofit2 everything seems to be working fine the status code is 200 (which means OK according…
Thorvald
  • 3,424
  • 6
  • 40
  • 66
2
votes
1 answer

Send Image file via Retrofit from Android to Spring

I am trying to upload Image via Retrofit to S3 via Spring. So, it's basically 2 tasks. Pass Image to Spring API From Spring API upload it to S3 Server. I know how to upload the Image to S3 and it works fine. My Problem is the first part. I have…
Avi Patel
  • 475
  • 6
  • 23
2
votes
2 answers

Post data in body with Retrofit2 and Kotlin: Unable to create call adapter

we have the problem to send a post request with body parameters. The JSON looks like: { "userId": 123456, "comment": "This is a comment" } We call the backend with the following interface: interface ServiceDetailsService { …
christoph
  • 303
  • 2
  • 8
2
votes
2 answers

Refresh Access Token Retrofit2 + RXJava2

This approach always worked when updating a token. That is, with each request if I received an error 401, the operator retryWhen() triggered it updated the token. Here is the code: private Observable refreshAccessToken() { …
No Name
  • 741
  • 8
  • 18
2
votes
2 answers

Retrofit request throwing UnknownHostException behind VPN

So I'm having an issue that looks that it came straight out from the Twilight Zone. Problem I have to hit a REST API endpoint from a backend, the thing is that in order to hit that endpoint I need to go through a VPN. Otherwise the host is not…
4gus71n
  • 3,717
  • 3
  • 39
  • 66
2
votes
1 answer

How I can DRY Android retrofit calls?

I have several repository classes in my code. For example, this is UserRepository: public class UserRepository { public static String TAG = "UserRepository"; ApiService mApiService; SharedPreferences mPrefs; Context…
igor_rb
  • 1,821
  • 1
  • 19
  • 34
1 2 3
99
100