posting to a remote url with expressjs

i have this in my server.js

app.post("/leadAPI/ed",function(request,response){
//api post code here
});

In this post request i need to post data contained in request body to some external API with a specific URL and send the response back using response.send. How to do it in a clean fashion. Is there anything build in for this in expressjs?

As Andreas mentioned, this isn't express's duty. Its duty is to invoke your function when an HTTP request comes in.

You can use node's built-in HTTP client, as Andreas also mentioned in a comment, to make a request to your external site.

Try something like this:

var http = require('http');

app.post("/leadAPI/ed", function(request, response) {
  var proxyRequest = http.request({
      host: 'remote.site.com',
      port: 80,
      method: 'POST',
      path: '/endpoint/url'
    },
    function (proxyResponse) {
      proxyResponse.on('data', function (chunk) {
        response.send(chunk);
      });
    });

  proxyRequest.write(response.body);
  proxyRequest.end();
});

I'm sure you'll need to adapt it to handle chunked responses and figure out the transfer-encoding, but that is the gist of what you need.

For details, see

http://nodejs.org/api/http.html

I would use Mikeal Rogers' request library for this:

var request = require('request');

app.post("/leadAPI/ed",function(req, res){
  var remote = request('remote url');

  req.pipe(remote);
  remote.pipe(res);
});