title: Reactor paginated web service calls
body: <p>I am using reactor in a spring project where I have to call a paginated api.
  The api returns something like this :</p>
  
  <pre><code>{
    "last": false,
    "totalPages": 2,
    "totalElements": 4178,
    "sort": {
      "sorted": false,
      "unsorted": true
    },
    "first": false,
    "numberOfElements": 1178,
    "size": 3000,
    "number": 0
  }
  </code></pre>
  
  <p>Now what I am trying to achieve is using webflux to call the server until last == true. </p>
  
  <p>I can't figure our what would be the right way to do that.</p>
  
  <p>What i have got so far is this :</p>
  
  <pre><code>Mono&lt;UserInfo&gt; firstUserInfo =  panelistService.getInactiveUserInfo(noOfDays, role, pageNo);
  
  
      Flux&lt;User&gt; listOfUsers = firstUserInfo.flatMap(fui -&gt;{
  
          logger.info("ACCOUNT SERVICE - purgeCronJob - Getting first page of inactive panelists -  page {} total {} last {} panelists {}", pageNo,fui.getTotalNoOfPages(),fui.isLast(),fui.getUserContent().size()); 
  
          Mono&lt;List&lt;User&gt;&gt; firstListOfUsers = Mono.just(fui.getUserContent());
  
          if(fui.isLast()) {
              return firstListOfUsers;
          }
  
          pageNo++;
          int totalPageNo = fui.getTotalNoOfPages();
  
          for(int i = pageNo; i &lt; totalPageNo; i++) {
  
              Mono&lt;List&lt;User&gt;&gt; lou = panelistService.getInactiveUserInfo(noOfDays, role, i).map(ui -&gt;{
                  logger.info("ACCOUNT SERVICE - purgeCronJob - Getting inactive panelists -  page {} total {} last {} panelists {}", pageNo,ui.getTotalNoOfPages(),ui.isLast(),ui.getUserContent().size()); 
                  return ui.getUserContent();
              }); 
              firstListOfUsers.zipWith(lou);
          }
  
          return firstListOfUsers;
  
      }).flatMapMany(Flux::fromIterable);
  
      listOfUsers.subscribe();
  </code></pre>
  
  <p>So in stead of getting the last value , i build all the mono for each page and zip them all together .</p>