Retrofit error-Missing either @GET URL or @Url parameter

AndroidRetrofitRetrofit2

Android Problem Overview


I am working on Youtube API. The base URL is <https://www.googleapis.com/youtube/v3/search/>

Request :GET

https://www.googleapis.com/youtube/v3/search?part=snippet&q={search_keyword}&key={API_KEY}

ApiService Interface code-

public interface ApiService {
    @GET("")
    Call<YoutubeResponse> searchVideos(@Query("part") String part,
                                   @Query("q") String q,@Query("key") String apiKey);
}

The error: java.lang.IllegalArgumentException: Missing either @GET URL or @Url parameter. in the line of code

Call<YoutubeResponse> call=service.searchVideos("snippet",s, URLConstants.Youtube_API_KEY);

I'm a beginner. Please help!

Android Solutions


Solution 1 - Android

It's much more semantically correct to use https://www.googleapis.com/youtube/v3/ as your base URL and then declare @GET("search/") on your service method.

That said, if you really want your base URL to be the full path you can use @GET(".") to declare that your final URL is the same as your base URL.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionankushbbbrView Question on Stackoverflow
Solution 1 - AndroidJake WhartonView Answer on Stackoverflow