Declaring a retrofit REST endpoint with constant query value



So I want to get the metadata of a youtube video (say this one: https://www.youtube.com/watch?v=qlTA3rnpgzU).

I’m going to encode it and wrap it in another url like so: http://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqlTA3rnpgzU&format=json

My interface definition will look like this:

public interface YoutubeApi {
    @GET ("oembed") 
    YoutubeMetaData metaData (@Query (QUERY_VIDEO_URL) final String url,
                              @Query(QUERY_FORMAT) final String alwaysJson);
}

That’s all fine and dandy, but I don’t ever want to specify any format other than JSON here (format=json is a fixed part of this url).

Is there a way to specify this in my interface declaration and reduce my interface to:

public interface YoutubeApi {
    @GET ("oembed") 
    @Magic ("format=json")
    YoutubeMetaData metaData (@Query (QUERY_VIDEO_URL) final String url);
}

Thanks.

Answer

Just put it right in the relative URL:

public interface YoutubeApi {
  @GET("oembed?format=json") 
  YoutubeMetaData metaData(@Query(QUERY_VIDEO_URL) String url);
}


Source: stackoverflow