Set dynamic base url using Retrofit 2.0 and Dagger 2

前端 未结 8 592
南旧
南旧 2020-11-27 12:36

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         


        
8条回答
  •  忘掉有多难
    2020-11-27 13:05

    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.

    This will use the base url

    provided by you while creating the instance of Retrofit.

    @GET("/product/123")
    fun fetchDataFromNetwork(): Call
    

    This ignore the base url

    and use the url you will be providing this call at run time.

    @GET()
    fun fetchDataFromNetwork(@Url url : String): Call //
    

提交回复
热议问题