Reputation: 1383
I need to try to get the full URL Retrofit is using for make API calls.
For example:
@GET("recipes/hot/")
suspend fun doCall(): Recipes
I want to somehow get the full URL (base url + paths etc.) that this API call is doing.
One solution I've found was:
@GET("recipes/hot/")
suspend fun doCall(): Response<Recipes>
Then you can get the url
from this response wrapper class.
However, the rest of the api calls in the codebase doesn't wrap the return type with Response
, so I really want to avoid doing this.
Is there some easy way I can get the full URL from a Retrofit api call?
Upvotes: 1
Views: 2242
Reputation: 88
You need to add interceptor logging on retrofit for debug mode which will provide you logs in Android Studio logcat while API hit and return response as well. Below is the example, Refactor it as per your need.
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
OkHttpClient.Builder httpclient = new OkHttpClient.Builder();
httpclient.addInterceptor(logging);
if (BuildConfig.DEBUG) {
// development build
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
// production build
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(WebServiceConstants.SERVER_URL)
.client(httpclient.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
Upvotes: 2