Dynamically add query parameters without value for revision request

I have a query that sets up a list of services that are enabled for a user.

The request has the following format:

https://myserver.com/setservices?param1=val1¶m2=val2&service[10†&service[1000-03&service[10000]

A list of service parameters ("service [10] and service [1000] and service [10000]") is created dynamically, and each parameter does not matter. Is it possible to do this with Retrofit?

+6
source share
2 answers

From the modified documentation :

For complex combinations of query parameters, you can use Map .

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

I think this will do what you want to achieve.

+15
source

I found a workaround on how to do this.

 @GET("/setservices{services_query}") ServicesSetResponse setServices(@EncodedPath("services_query") String servicesQuery); 

And then:

 getService().setServices("?param1=val1&param2=val2" + "&services[10]&services[100000]&services[1000000]") 
+5
source

Source: https://habr.com/ru/post/976033/


All Articles