Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!