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
2 answers

Trying to POST with no body using Retrofit failing with GSON parsing exception

I'm integrating with a REST API so I'm using Retrofit. The url I need to hit is: http://{{server}}/api/v1/stuff/{{id}}/deactivate I've created an interface that implements the API: @PUT("/api/v1/stuff/{id}/deactivate") String deactivate(@Path("id")…
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
3
votes
1 answer

How to notify a single listener on every failed Httprequest with Retrofit on Android

I use Retrofit to connect my app to a webbackend. We use the asynchronous callback methods to do requests at different points in the app. How would I add a listener that is notified every time a http-request fails. My current idea is to create a…
Janusz
  • 187,060
  • 113
  • 301
  • 369
3
votes
1 answer

StackExchange API handling with Retrofit

I am in the process of writing a neat Android application to interact with the API, that follows the Google Android user experience. The application will be using Retrofit (to make REST-api mechanisms easier). Now, I have created Java classes that…
t0mm13b
  • 34,087
  • 8
  • 78
  • 110
3
votes
1 answer

NoClassDefFoundError for retrofit.RestAdapter$Builder

I'm using Android Studio and I would like to use Retrofit, a rest client for Android and Java. I added retrofit in dependencies of my build.gradle file. So, I can use it on my project but when I would like to execute it, I have a…
3
votes
1 answer

okhttp+retrofit - Lots of threads in monitor state

I have build an app where I used Okhttp and retrofit. Everything works fine except some irregular wired behaviour. In this news app I trigger feed download request for multiple sections. Time to time requests never return any response (not even…
Mohammad Haque
  • 565
  • 1
  • 7
  • 16
3
votes
2 answers

How can I configure Square's Retrofit Client to handle a request with a variable number of parameters

I'm building an Android App and am using Square's Retrofit library for short-lived network calls. I'm relatively new to Java and Android. Until now I've constructed requests like so: @GET("/library.php") void library( @Query("one_thing")…
Alfie Hanssen
  • 16,964
  • 12
  • 68
  • 74
3
votes
2 answers

Android Retrofit Causes Socket Timeout Exception

I am making a POST call to a tomcat server running Struts2 using the retrofit library on an Android Galaxy S3 (/Nexus 7) device. The POST call fails. The tomcat log shows Socket timeout exception. The same POST using the exact same headers done via…
K K
  • 101
  • 1
  • 8
2
votes
1 answer

POST to Gin fails when it comes from my Android app, but succeeds when from Postman

I'm not quite sure which side is the cause of the issue, but it seems that the request gets received by Gin but doesn't allow the request from the android app. The endpoint I'm trying to POST to is related to a monolith model which has a type…
rminaj
  • 560
  • 6
  • 28
2
votes
2 answers

How to send multipart with images using Retrofit2?

I need to send the same data from the following image (Postman) I'm using Retrofit with Coroutines, I tried to use the following snippet to send the request: @POST("ia") @Multipart suspend fun getMeasurement( @HeaderMap authenticationHeaders:…
RafaelFerreira
  • 125
  • 1
  • 10
2
votes
1 answer

Parse JSON string to a list of objects in Kotlin Android (MOSHI?)

In my app, I'm using Retrofit to get the data from API (with flights data). I want to obatin List< Itinerary > from JSON, but the problem is that it is badly formatted, and I'm getting the itineraries seperately. I heard that it's possible to do…
deja
  • 176
  • 10
2
votes
1 answer

How to reinit singleton in Hilt (Android)?

I have Hilt DI framework in my Android project. Also I have retrofit, and ApiNetworkModule for getting singleton retrofit object: @Module @InstallIn(SingletonComponent.class) public class ApiNetworkModule { ... @Singleton @Provides …
Alex D.
  • 1,424
  • 15
  • 40
2
votes
0 answers

Is there any new XmlConverter to use with retrofit in android?

Today i encountered this question What kind of XmlConverter can I use for Retrofit in Android? When looking for a problem i'm having, and i wondered if there are any new xml conversion library that i can use with retrofit in android. As it is an old…
Void
  • 969
  • 1
  • 11
  • 19
2
votes
2 answers

Is it possible to read binary file with retrofit using flutter?

I have a binary file I need to read its contents using retrofit for my flutter application. I want to know if this could be possible or not. if yes, any links, please? Otherwise, I need some recommendations. Thanks in advance for your help
rania
  • 63
  • 6
2
votes
0 answers

Get JSON result inside an OBJECT using Kotlin and Retrofit

I need to GET an JSON result but it's inside an JSON Object. I search but only found responses in Java. Someone can help me to GET the "from, to and amount" inside the request{}? HERE's THE API RESULT My GET code: @GET("convert") fun…
2
votes
1 answer

How to return a List field as an empty list "[]" in Android Studio?

So I have been tackling this issue for a couple of days now. I have a Data class that is used to send information back into the API. In this instance, I have this x amount of fields. In these fields, there are three List fields with different types,…
OEThe11
  • 341
  • 2
  • 11
1 2 3
99
100