Annotation Type QueryParam


  • @Retention(RUNTIME)
    @Target(PARAMETER)
    public @interface QueryParam
    Annotation for query parameters to be appended to a REST API Request URI.

    Example 1:

     @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/resources")
     Single<RestResponseBase<Headers, Body>> listByResourceGroup(@PathParam("resourceGroupName") String
     resourceGroupName, @PathParam("subscriptionId") String subscriptionId, @QueryParam("$filter") String
     filter, @QueryParam("$expand") String expand, @QueryParam("$top") Integer top, @QueryParam("api-version") String
     apiVersion);

    The value of parameters filter, expand, top, apiVersion will be encoded and encoded value will be used to replace the corresponding path segment {$filter}, {$expand}, {$top}, {api-version} respectively.

    Example 2: (A use case where PathParam.encoded=true will be used)

    It is possible that, a path segment variable can be used to represent sub path:

     @GET("http://wq.com/foo/{subpath}/values")
      String getValues(@PathParam("subpath") String param, @QueryParam("connectionString") String connectionString);

    In this case, if consumer pass "a=b" as the value for query then the resolved url looks like: "http://wq.com/foo/paramblah/values?connectionString=a%3Db"

    For such cases the encoded attribute can be used:

     @GET("http://wq.com/foo/{subpath}/values")
      String getValues(@PathParam("subpath") String param, @QueryParam("query", encoded = true) String query);

    In this case, if consumer pass "a=b" as the value for param1 then the resolved url looks as expected: "http://wq.com/foo/paramblah/values?connectionString=a=b"

    Example 3:

     @GET("http://wq.com/foo/multiple/params")
      String multipleParams(@QueryParam("avoid", multipleQueryParams = true) List<String> avoid);

    The value of parameter avoid would look like this: "http://wq.com/foo/multiple/params?avoid%3Dtest1&avoid%3Dtest2&avoid%3Dtest3"

    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String value
      The name of the variable in the endpoint uri template which will be replaced with the value of the parameter annotated with this annotation.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean encoded
      A value true for this argument indicates that value of value() is already encoded hence engine should not encode it, by default value will be encoded.
      boolean multipleQueryParams
      A value true for this argument indicates that value of value() should not be converted to Json in case it is an array but instead sent as multiple values with same parameter name.
    • Element Detail

      • value

        String value
        The name of the variable in the endpoint uri template which will be replaced with the value of the parameter annotated with this annotation.
        Returns:
        The name of the variable in the endpoint uri template which will be replaced with the value of the parameter annotated with this annotation.
      • encoded

        boolean encoded
        A value true for this argument indicates that value of value() is already encoded hence engine should not encode it, by default value will be encoded.
        Returns:
        Whether or not this query parameter is already encoded.
        Default:
        false
      • multipleQueryParams

        boolean multipleQueryParams
        A value true for this argument indicates that value of value() should not be converted to Json in case it is an array but instead sent as multiple values with same parameter name.
        Returns:
        Whether or not this query parameter list values should be sent as individual query params or as a single Json.
        Default:
        false