Search code examples
javaandroidkotlingradleretrofit

fetching data from api using baseUrl from variant in android


I have two variants in my gradle file , each variant has different BaseUrl , for fetching data from api i"m using retrofit , now that i'm using BuildConfig to pass the BaseUrl based on the variant selected , if i pass whole url to baseUrl("") function , is it okey to leave @GET("") empty ? it is not working for me !! , i appreciate any help , Thank you

enter image description here

enter image description here

enter image description here


Solution

  • You could just use empty GET and pass full url with @Url retrofit annotation as query parameter

    interface ApiService {
      @GET
      suspend fun getSimpson(@Url url: String): ApiModel
    }
    

    while invoking the method

    getApiService().getSimpson(BuildConfig.BASE_URL)