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
2
votes
1 answer

I am using retrofit and my output is not showing on even if there is no error

The output is not displayed even if there is no error and I can't seem to comprehend where I am making a mistake. It will be helpful if someone finds my error in code and help me to rectify it Model class public class TopAnime { private Integer…
amun
  • 21
  • 4
2
votes
3 answers

Unable to generate g.dart with retrofit flutter

I am migrating my flutter project to 3.3.0 and i am calling API with retrofit which was working fine, after upgrading all packages i delete .g.dart file and run the following command to rebuild the .g.dart file flutter pub run build_runner build it…
Ahmad Raza
  • 758
  • 7
  • 26
2
votes
1 answer

Flutter Retrofit, using different base urls for development and deployment

I use retrofit to generate my api client in dart/flutter. I have a version of the server on my local machine and a version hosted. I want to use the local machine as the base url during development and testing, and a different base url when I build…
Nelson
  • 43
  • 4
2
votes
0 answers

java.lang.NullPointerException: Cannot invoke "org.springframework.web.multipart.MultipartFile.getOriginalFilename()" because "file" is null

I am able to upload image using postman but while uploading image from android app. I am facing the error. please help me for the fix this error java.lang.NullPointerException: Cannot invoke…
Ankush
  • 91
  • 6
2
votes
1 answer

Retrofit - OkHttp Authenticator- How to make other api calls pause till the authenticator completes execution

I am having multiple api calls going in a screen launched with viewmodel scope like this in viewmodel viewModelScope.launch { apiCallOne() } viewModelScope.launch { apiCallTwo() } viewModelScope.launch { apiCallThree() } And my…
Harish Padmanabh
  • 307
  • 4
  • 17
2
votes
2 answers

How to fix api call working in browser but 403 in android studio

Hi i'm wondering why my API call works in browser but when called in Android studio I get a 403 error. The Debug D/OkHttp: <-- 403 https://api.boblop.com/search/api/rest/v3/catalog/products/search/keyword?q=asesea&key=esaesaesae (106ms) D/OkHttp:…
Inveniuum
  • 31
  • 4
2
votes
1 answer

show data's to a recyclerview from 2 different APIs. How to combine responses from 1st api and selected fields from 2nd API responses

i have query related to multiple api calls . I need to show data's to a recyclerview from 2 different API responses. How to combine all responses from first api and selected fields from 2nd API responses Eg : Api1 - [{ "item_id :…
2
votes
1 answer

How to handle 204 response in Retrofit using Dart?

I'm using retrofit: ^3.0.1+1 and retrofit_generator: ^4.0.3+1 with Flutter and Dart. I have a Retrofit method as such: @GET(ApiDashboard.urlFaults) Future>> fetchFaults({ @Query(ApiDashboard.queryKey) required…
Nort
  • 117
  • 9
2
votes
2 answers

POST authorization request to Spotify Api with Retrofit

I am trying to use Spotify API. But as the given auth token expires every hour, so I have to post a request to API to get a new one. I found a code on the official website that shows how to do it. var client_id = 'CLIENT_ID'; var client_secret =…
jane
  • 124
  • 10
2
votes
1 answer

Retrofit in object form

I have an MVVM program that uses Retrofit and Hilt I have two questions: Why the most examples the Retrofit was created in object form instead of class form? Why we shouldn't implements (inheritance) the AppModule from Retrofit to make a limitation…
Ali Doran
  • 378
  • 1
  • 12
2
votes
2 answers

How to retry only requests that resulted in 500 and did it below given time threshold?

Tech stack: rx-java 1.1.x, retrofit 1.9.x, spring 4.3.x. A bit of context: I'm pretty new to rx-java. My service A has an API endpoint that makes a search call to service B that is frequently used, and fails a bit too often then it should. Some of…
Eel Lee
  • 3,513
  • 2
  • 31
  • 49
2
votes
1 answer

OkHttpClient java.net.SocketTimeoutException: timeout

I have a class where I prepare my OkHttpClient and add an Interceptor to it for my Retrofit requests in Android Studio. There it assigns default parameters in all requests. It works fine, except when I need to make requests with a high timeOut (a…
Fernando
  • 43
  • 1
  • 5
2
votes
0 answers

Cant access nested list in Json response

Im trying to access some list items from a json response using retrofit but cant seem to be able to access using get method. The ListQuotes seems to be saying null @JsonPropertyOrder({ "page", "last_page", "quotes" }) public class…
2
votes
1 answer

Flutter - using retrofit with injectable

I am trying to use retrofit along with injectable I am following clean architecture, and in the repo class i want to inject the retrofit client but i cant annotate the client with injectable since its abstract and i cant annotate the implementation…
2
votes
0 answers

java.lang.IllegalStateException: Trying to get a LocalDate

I´m trying to get a LocalDate with Retrofit but it doesn´t works. I get this error: E/Error: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 35 path $[0].fecha_alta Error Retrofit class: public class Client…
ProFra
  • 21
  • 3
1 2 3
99
100