pdegand59 pdegand59 - 1 year ago 320
Android Question

Retrofit 2 - Dynamic URL

With Retrofit 2, you can set a full URL in the annotation of a service method like :

public interface APIService {
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 {
Call<Users> getUsers(@Path("fullUrl") fullUrl);

new Retrofit.Builder()
.getUsers("http://api.mysite.com/user/list"); // this url should be dynamic

But here, Retrofit doesn't see that the path is actually a full URL and is trying to download

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

Thank you

Answer Source

I think you are using it in wrong way. Here is an excerpt from the changelog:

New: @Url parameter annotation allows passing a complete URL for an endpoint.

So your interface should be like this:

public interface APIService {
    Call<Users> getUsers(@Url String url);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download