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 use Retrofit 2 with full dynamic URL.

I tried to set a full path like :

public interface APIService {
  @GET("{fullUrl}")
  Call<Users> getUsers(@Path("fullUrl") fullUrl);
}

new Retrofit.Builder()
  .baseUrl("https://api.mysite.com/")
  .build()
  .create(APIService.class)
  .getUsers("http://api.mysite.com/user/list"); // this url should be dynamic
  .execute();

But here, Retrofit doesn’t see that the path is actually a full URL and is trying to download http://api.mysite.com/http%3A%2F%2Fapi.mysite.com%2Fuser%2Flist

Any hint of how I could use Retrofit with such dynamic url ?

Thank you

9 Answers
9

Leave a Reply

Your email address will not be published. Required fields are marked *