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

171
Visualizações
Send separate requests instead of one whole in Angular

I want to modify this function to send these two file ids in the separate requests:

return this.upload(myForm).pipe(
  take(1),
  switchMap(res => {
    body.user.profilePic = res.data.profilePic;
    body.user.coverPic = res.data.coverPic;

    return this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body);
})
);

Should I use flatmap?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can do separate requests from one pipe like that:

return this.upload(myForm).pipe(
  take(1),
  switchMap(res => {
    body.user.profilePic = res.data.profilePic;
    body.user.coverPic = res.data.coverPic;

    return [
      this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body),
      this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body),
    ]
  }),
  mergeAll(),
);
over 4 years ago · Santiago Trujillo Relatório

0

The right operator depends on whether you want to send the two request in parallel or consecutively.

If you already have take(1) then you can use both switchMap or mergeMap because it will always emit only once and thus it doesn't matter in this case.

Sending requests in parallel:

return this.upload(myForm).pipe(
  take(1),
  switchMap(res => {
    ...
    return forkJoin([
      this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body),
      this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body),
    ]);
  }),
);

Sending requests in sequence:

return this.upload(myForm).pipe(
  take(1),
  switchMap(res => {
    ...
    return concat(
      this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body),
      this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body),
    );
  }),
);
over 4 years ago · Santiago Trujillo 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