3

I'm working on REST API client for Android using Retrofit. Some of the use something like this http://my.backend.com and others use https://my.backend.com. The way I found is to create two separate interfaces and build two RestAdapters with different endpoints. But I would like to keep my interfaces consitent and I'm wondering if it is possible for example build my Res adapter with my.backend.com and specify if the methot thould use https with @HTTPS annotation ? Thanks.

oleg.semen
  • 2,901
  • 2
  • 28
  • 56

2 Answers2

0

The only thing you can change on a RestAdapter after it's been built is the log level so I'm afraid the only solution is to have two RestAdapters. Two seperate interfaces should not be necessary though, as long as the path after your endpoint (my.backend.com) is the same for both the http and the https version.

Toon Borgers
  • 3,638
  • 1
  • 14
  • 22
-1

You can do the following generic method which returns retrofit and keep just one interface. "baseUrl" can be either "http" or "https" urls.

public static Retrofit getRetrofit(@NotNull String baseUrl) {
    return new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}
MetaPlanet
  • 129
  • 4