retrofit / retrofit2.http / Query

Query

@Target([AnnotationTarget.VALUE_PARAMETER]) class Query

Query parameter appended to the URL.

Values are converted to strings using Retrofit#stringConverter(Type, Annotation[]) (or Object#toString(), if no matching string converter is installed) and then URL encoded. null values are ignored. Passing a List or array will result in a query parameter for each non-null item.

Simple Example:


  @GET("/friends")
  Call<ResponseBody> friends(@Query("page") int page);
  
Calling with foo.friends(1) yields /friends?page=1.

Example with null:


  @GET("/friends")
  Call<ResponseBody> friends(@Query("group") String group);
  
Calling with foo.friends(null) yields /friends.

Array/Varargs Example:


  @GET("/friends")
  Call<ResponseBody> friends(@Query("group") String... groups);
  
Calling with foo.friends("coworker", "bowling") yields /friends?group=coworker&group=bowling.

Parameter names and values are URL encoded by default. Specify encoded=true to change this behavior.


  @GET("/friends")
  Call<ResponseBody> friends(@Query(value="group", encoded=true) String group);
  
Calling with foo.friends("foo+bar")) yields /friends?group=foo+bar.

See Also
QueryMapQueryName

Constructors

<init>

Query(value: String, encoded: Boolean)

Query parameter appended to the URL.

Properties

encoded

val encoded: Boolean

Specifies whether the parameter name and value are already URL encoded.

value

val value: String

The query parameter name.