6

How to make HTTP GET request in URL that has params appended by & using Retrofit in Android?

URL: http://api.com?name=remote&class=TV

Currently, i am using:

@GET("http://api.com?name={name}&class={class}")
    Call<CustomType> get(
            @Path(value = "name",encoded = false) String name,
            @Path(value = "class",encoded = false) String class);

I am getting following error:

java.lang.IllegalArgumentException: URL query string "name={name}&class={class}" 
must not have replace block. 
For dynamic query parameters use @Query.
Malwinder Singh
  • 6,644
  • 14
  • 65
  • 103

1 Answers1

20

It's a standard GET request url. Just use @Query:

@GET("http://api.com")
Call<CustomType> get(
        @Query("name") String name,
        @Query("class") String classs);

It will access url: http://api.com?name=remote&class=TV

rafakob
  • 3,946
  • 3
  • 26
  • 36