Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

70
Visualizações
Concat undetermined api call using rxjs

I would like query an Api that returns dada and next item that contains the next url to call.

When next is null it means that all data is sent.

  getData(url?: any) {
    if (!url) {
      url = `https....../geojson/geo/?srid=xxx&code=xx&jsonb_as_text=false&page_size=10`;
    }
    return this.httpClient.get(url, { headers }).pipe(
      flatMap((res: any) => {
        if (res.next) {
          this.getData(res.next);
        }
        return res;
      })
    );
  }

Actually the component only gets the first call but not the second.

How can I chain well api calls and concat the results then?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You probably want to use expand operator. It is recursive - each response calls the operator callback. You can use toArray to collect all responses as an array. You could use scan or no operator to process immediate results while the others are loading.

getData(url) {
   return this.httpClient.get(url, { headers })
}

getAllData() {
  
    const url = `https....../geojson/geo/?srid=xxx&code=xx&jsonb_as_text=false&page_size=10`;
    
    return this.getData(url).pipe(
      expand((res: any) => {
        if (res.next) {
          return this.getData(res.next);
        }
        return EMPTY;
      }),
      toArray(),
      map(responses => responses.flatMap(response => response.items))
    );
  }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda