How to force the reading of all existing REST results on a page?

Asked

Viewed 499 times

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’m making a query on a server REST which returns me 50 results at a time and pages the rest of the records probably to improve traffic management and not overload the server.

I want to return all the records on one page and I think I can do it using one for or foreach to tell the query that until you finish uploading all the records, you continue searching between the pages and listed the records, all in one page.

I think the solution is to read this pagination inside the foreach with another loop but I don’t know how to apply. If you want to take a look at the page, HERE

Question: How to extract all data on a single page by traversing through the Trials and bringing the results?

inserir a descrição da imagem aqui

3 answers

1

See if in the answer of your request the API returns a header with the total number of pages. Usually REST Apis return this. I haven’t seen your code, so use the example below just to understand the 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
    }
}

1

This depends on the application that runs on the server. If the application allows you to pass a parameter so that more records appear per page then you can do this with a request only.

If there is no such possibility, you will have to iterate over each page, where each page will be an HTTP request. The parameter page should be passed by POST so you can get the result of a page, see image below:

Parametro que deve ser passado para obter uma página

  • The application does not allow me to pull more records so I need to use the second option which is to iterate under each page but do not know how to do it!!! Can you help me?

  • You can already iterate on the first page, right?

  • Yes, the first page I have the first 50 records but I need all the records to appear on it and that’s what I can’t do.

  • But this you will not be able to do at once. To solve, you will need to pass a parameter to your HTTP request. This parameter goes via POST and is called a page. Try a test by passing the page parameter with value 2 and see the result.

  • I’ve already done it. In the very image you posted there is this pagination. But I need all the results on one page just to take it all and register it in the database.

  • @Marcosvinicius, you see. It is not possible to have all resutaldos in one page, because the application limits you. What you should do is loop according to the number of pages and, each iteration of this loop, you should make an HTTP request to the current page and feed your database. Therefore, if they are 3 pages, they are three loop iterations. The restriction is not in their application, it is in the application of the properties. You therefore need to suit yourself to this.

  • I don’t know how to do this iteration. You can help me?

Show 2 more comments

0

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

Advising not to make a foreach, just make the request according to the user’s demand. What can help in the user response time of your system.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.