Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda