Refreshing OAuth token using Retrofit without modifying all calls

We are using Retrofit in our Android app, to communicate with an OAuth2 secured server. Everything works great, we use the RequestInterceptor to include the access token with each call. However there will be times, when the access token will expire, and the token needs to be refreshed. When the token expires, the next call … Read more

Retrofit 2 – Dynamic URL

With Retrofit 2, you can set a full URL in the annotation of a service method like : public interface APIService { @GET(“http://api.mysite.com/user/list”) Call<Users> getUsers(); } However, in my app, the URL of my webservices are not known at compile time, the app retrieves them in a downloaded file so i’m wondering how i can … Read more

When should one use RxJava Observable and when simple Callback on Android?

I’m working on networking for my app. So I decided to try out Square’s Retrofit. I see that they support simple Callback @GET(“/user/{id}/photo”) void getUserPhoto(@Path(“id”) int id, Callback<Photo> cb); and RxJava’s Observable @GET(“/user/{id}/photo”) Observable<Photo> getUserPhoto(@Path(“id”) int id); Both look pretty similar at first glance, but when it gets to implementation it gets interesting… While with … Read more

Logging with Retrofit 2

I’m trying to get the exact JSON that is being sent in the request. Here is my code: OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor(){ @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException { Request request = chain.request(); Log.e(String.format(“\nrequest:\n%s\nheaders:\n%s”, request.body().toString(), request.headers())); com.squareup.okhttp.Response response = chain.proceed(request); return response; } }); Retrofit retrofit = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create()) … Read more

Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 5 years ago. Improve this question Two-part question from an iOS developer learning Android, working on an Android project that will make a variety of … Read more