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

202
Visualizações
node request-promise doesn't work with pipe() for a POST request with body

My service dispatches a POST request with some body coming from one service to another. Existing implementation works for GET request:

var rp = require('request-promise');

public pipe(options: Options, req: Request, res: Response): void {
  rp(options).pipe(res);
}

I wanted to use it for POST requests as well. Unfortunately it doesn't work when I'm passing a body to options. Method public pipe(options: Options, req: Request, res: Response) is reached, but no further request is coming out of my service. Without body a request is dispatched properly. I'm calling this method like this:

streamFromService(
req: Request,
res: Response,
serviceId: string,
servicePath: string,
query?: URLSearchParams): void {
const forwardHeaders = getForwardHeaders(req);
Promise.resolve(this.serviceLookup.lookup(serviceId, req.headers))
  // create URL parameter based on the given method parameters
  .then((url) =>
    query
      ? { ...url, pathname: servicePath, search: query.toString() }
      : { ...url, pathname: servicePath }
  )
  // create the URL
  .then((url: any) => URL.format(url))
  // tap(c => console.log('URL>', c)).
  .then((url) => {
        req.method.toUpperCase() === 'POST' ?
            this.httpClient.pipe(
                {method: 'POST', body: req.body, url: url, headers: forwardHeaders},
                req,
                res
            ) :
            this.httpClient.pipe(
                {url: url, headers: forwardHeaders},
                req,
                res
            );
      }
  )
  // tap(console.log).
  .tapCatch((err) =>
    console.error('Error for ', serviceId, servicePath, err)
  );}

What is worth mentioning is that before calling pipe() I'm retrieving some information from req like for mapping headers with req.headers. Is there a solution for my problem in piping a post request with body?

about 4 years ago · Juan Pablo Isaza
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