Dynamically add query parameters without value to Retrofit request

Yuriy picture Yuriy · Sep 29, 2014 · Viewed 11.2k times · Source

I have request that set list of services that are turned on for user.

Request has following format:

https://myserver.com/setservices?param1=val1&param2=val2&service[10]&service[1000]&service[10000]

List of service parameters ("service[10]&service[1000]&service[10000]") is created dynamically and each parameter doesn't have value. Is it possible to achive this using Retrofit?

Answer

WojciechKo picture WojciechKo · Sep 30, 2014

From the retrofit documentation:

For complex query parameter combinations a Map can be used.

@GET("/group/{id}/users")
List<User> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options);

I guess this will make what you want to achieve.