U
U
uaSaint2015-08-13 13:38:40
Java
uaSaint, 2015-08-13 13:38:40

How to query multiple pages?

Hello,
There is an api, a request to which gives a maximum of 1000 results and then standard pagination, i.e. is page={1,...,n}. The question is how to execute the query correctly and get all the data using retrofit ? I understand that you can check the response.body, but how to implement this does not reach. I don't want to use loops and recursion. The call goes like this ( getCities takes the page as the first parameter, if this is not done, the result is still limited to 1000 objects ):

mService.getCities(1, new Callback<GetCitiesResponse[]>() {
            @Override
            public void success(GetCitiesResponse[] getCitiesResponses, Response response) {
                Log.i(LOG_TAG, "Founded " + String.valueOf(getCitiesResponses.length) + " items");
            }

            @Override
            public void failure(RetrofitError error) {
                error.printStackTrace();
            }
        });

actually it is clear that you need to substitute 2,3, etc. until the body of the response is empty, but I would not like to fence anything extra ...
PS do not kick too much, because I'm using retrofit for the first time.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question