Questions tagged [retrofit]

Retrofit is a type-safe REST client for Android and Java by Square, Inc.

Retrofit turns REST API into a Java interface.

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

The RestAdapter class generates an implementation of the GitHubService interface.

RestAdapter restAdapter = new RestAdapter.Builder()
   .setEndpoint("https://api.github.com")
   .build();

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

Each call on the generated GitHubService makes an HTTP request to the remote webserver.

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

Annotations are used 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

The library is open sourced under Apache 2.0 license.

References

8574 questions
3
votes
0 answers

How to post Multiple files to server using Retrofit in Android?

I am trying to post multiple files using Retrofit but always i am getting error failure null In Activity Code : MultipartTypedOutput multipartTypedOutput = new MultipartTypedOutput(); multipartTypedOutput.addPart("test_image", …
Girish Patel
  • 1,270
  • 4
  • 16
  • 30
3
votes
1 answer

Retrofit with Kotlin traits that include implemented methods

Traits work well with Retrofit as long as there is no extra method implemented. Depending on return type RetrofitError: TwitchApi.someMethod: HTTP method annotation is required (e.g., @GET, @POST, etc.). or java.lang.IllegalArgumentException:…
atok
  • 5,880
  • 3
  • 33
  • 62
3
votes
2 answers

retrofit @POST parameters are sent via GET

I am trying to send multiple parameters (as I usually do) with @QueryMap but via POST this time using retrofit. Retrofit API @POST("/request.php") void sendRequest(@QueryMap Map parameters, retrofit.Callback
Bartu
  • 2,189
  • 2
  • 26
  • 50
3
votes
2 answers

Receiving custom parameter in retrofit callback

This is my post : @POST("/path") @FormUrlEncoded void postIt(@Field("id") String id , Callback response); and this is the Callback: private Callback responseCallBack = new Callback() { @Override public void…
user3473590
3
votes
0 answers

PUT Request fails on android Lollipop

Following the REST API, I encounter an error while using the PUT method through retrofit call. The error occurs only in Lollipop version of android whereas it works fine on the other O.S. as tested thoroughly . I am sending data in the body of the…
3
votes
0 answers

Google search with Retrofit

I am trying to learn Retrofit and want to use it for Google search. I have written following code: public class RetrofitSample { private static final String URL = "https://www.google.com"; interface Google { …
Mukaddes
  • 307
  • 2
  • 12
3
votes
0 answers

retrofit forcing ui to freeze

I recently started using retrofit libraries.. long story short, my UI is getting frozen, until all retrofit calls are completed.. point to be noted in the place of retrofit if you are using async task then the UI has no problem there is no…
Alvin
  • 416
  • 1
  • 8
  • 18
3
votes
3 answers

Formatting a RetroFit post request for rails API

All, I'm starting to user RetroFit for the first time, and it's pretty awesome. That said, I'm running into a road block when formatting a POST request. The API I'm using specifies that to create a user, I need to send the user object like…
coder
  • 10,460
  • 17
  • 72
  • 125
3
votes
3 answers

Retrofit. Android. Can I download json object to String without parsing?

Can I download json object as a String without parsing with Retrofit on Android device? When I tried direct approach @GET("/api.php?action=bundle") public void getWholeScheduleString(Callback response); I got…
Besuglov Sergey
  • 506
  • 5
  • 20
3
votes
1 answer

Unable to resolve superclass of Landroid/support/v4

After installing my app, it only runs the first time correctly and after that it crashes every time. All needed dependencies are included and up-to-date. I already tried to clean the project and rebuild it with different version of the libraries and…
3
votes
1 answer

Retrofit Response Error with Content type text/html

I am having issue with an API service , https://api.litzscore.com/rest/v2/recent_matches/ I think the issue is with their Response Header Content type,When i contacted them they said like this Its should be possible to load the response as string…
Saleeh
  • 392
  • 4
  • 15
3
votes
2 answers

How to configure debug and release log level for Retrofit?

I use Retrofit in my Android project. While developing I enable full log output for the RestAdapter as follows: new RestAdapter.Builder() .setLogLevel(RestAdapter.LogLevel.FULL); When I bake a release the log level is set to…
JJD
  • 50,076
  • 60
  • 203
  • 339
3
votes
1 answer

java.net.ProtocolException: Unexpected status line: HTTP/1.1 422��Unprocessable Entity

I'm making a POST request using Retrofit + Okhttp, and I'm running into the following error: 02-05 04:45:13.981 15972-16249/com.myapp.android D/Retrofit﹕ ---> HTTP POST http://10.0.0.4:3000/api/v1/users/1/posts 02-05 04:45:13.981 …
loeschg
  • 29,961
  • 26
  • 97
  • 150
3
votes
0 answers

Connection timeout error retrofit android

I am using Retrofit. The server is responding with correct data but when I implemented the stuff on app it's not working. 01-28 22:24:58.546: I/System.out(30595): [CDS]EAGAIN or EWOULDBLOCK in Recvfrom 01-28 22:24:58.546: I/System.out(30595):…
Rahul Saxena
  • 69
  • 1
  • 10
3
votes
1 answer

Add Retrofit Requestinterceptor with Dagger at runtime

I'm using dagger and retrofit. I inject my Retrofit services with Dagger. Now i wanna do a authorization request to get an accessToken. Afterwards i want to enhance my api module with an Request interceptor to use this access token for future…
AdrianoCelentano
  • 2,461
  • 3
  • 31
  • 42