I\'m trying to perform a login action using Retrofit 2.0 using Dagger 2
Here\'s how I set up Retrofit dependency
@Provides
@Singleton
Retrofit provid
This might be late but Retrofit
allows you to use dynamic URLs while making the network call itself using @Url
annotation.
I am also using Dagger2
to inject the Retrofit
instance in my repositories and this solution is working fine for me.
provided by you while creating the instance of Retrofit.
@GET("/product/123")
fun fetchDataFromNetwork(): Call<Product>
and use the url you will be providing this call at run time.
@GET()
fun fetchDataFromNetwork(@Url url : String): Call<Product> //
Retrofit2 library comes with a @Url
annotation. You can override baseUrl
like this:
API interface:
public interface UserService {
@GET
public Call<ResponseBody> profilePicture(@Url String url);
}
And call the API like this:
Retrofit retrofit = Retrofit.Builder()
.baseUrl("https://your.api.url/");
.build();
UserService service = retrofit.create(UserService.class);
service.profilePicture("https://s3.amazon.com/profile-picture/path");
For more details refer to this link: https://futurestud.io/tutorials/retrofit-2-how-to-use-dynamic-urls-for-requests