How to force read all the results in REST on a page?

3
foreach ($result as $indices) {

    // Aqui ele retorna 50 registros por conuslta
    echo $indices['Empreendimento'];

    // Provavelmente preciso de um loop da paginação aqui dentro
    // para falar para o foreach que enquanto houver paginação, que
    // ele continue buscando e listando os registros

}

I am doing a query on a REST server which returns me 50 results at a time and makes paging of the rest of the records likely to improve traffic management and not overload the server.

I want to return all the records on a single page and I think I can do this using a for or foreach to tell the query that while not loading all the records, keep searching between the pages and listing the records, all on one page.

I think the solution is to read this paging within foreach with another loop but I do not know how to apply. If you would like to take a look at the page, HERE

Question: How to extract all the data in a single page by scrolling through the pages and bringing the results?

    
asked by anonymous 28.11.2015 / 15:10

3 answers

1

This depends on the application running on the server. If the application allows you to pass a parameter so that more records appear per page there you will be able to do this with only one request.

If this is not possible, you will have to iterate over each page, where each page will be an HTTP request. The page parameter must be passed through POST so that you can get the result of a page, see image below:

    
28.11.2015 / 15:35
1

See if in the response of your request the API returns a header with the total number of pages. Usually REST APIs return this. I did not see your code, so use the example below just to understand logic.

$primeiraRequisicao = $api->imoveis();
//Retorno da API para o total de páginas
$pages = $primeiraRequisicao->totalPages;
if($pages > 1)
    for($i = 2; $i <= $pages; $i++){
        //O parâmetro é o número da página
        $api->imoveis($i);
        //Junte os resultados da sua requisição
        //com a primeira requisição feita antes da iteração
    }
}
    
29.11.2015 / 05:15
0

So if the API server already has a limit it is for the response time to be faster.

Conclude not to make a foreach, just make the request according to user demand. This can help with the response time of the user of your system.

    
07.12.2015 / 03:34