Add an array as request parameter with Retrofit 2

François Legrand picture François Legrand · Jan 11, 2017 · Viewed 17.8k times · Source

I'm looking for way to add an int array (e.g [0,1,3,5]) as parameter in a GET request with retrofit 2. Then, the generated url should be like this : http://server/service?array=[0,1,3,5]

How to do this ?

Answer

Andrej Jurkin picture Andrej Jurkin · Jan 11, 2017

Just add it as a query param

@GET("http://server/service")
Observable<Void> getSomething(@Query("array") List<Integer> array);

You can also use int[], or Integer... as a last param;