Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically add query parameters without value to Retrofit request

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?

like image 957
Yuriy Avatar asked Sep 29 '14 21:09

Yuriy


People also ask

What is query annotation in retrofit?

Retrofit uses annotations to define query parameters for requests. The annotation is defined before method parameters and specifies the request parameter name. The desired value for this parameter is passed during method call.

Can we pass parameters in GET request?

get() method. Using the params property we can pass parameters to the HTTP get request. Either we can pass HttpParams or an object which contains key value pairs of parameters.


1 Answers

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.

like image 186
WojciechKo Avatar answered Oct 11 '22 17:10

WojciechKo