Extending others webservices

I was wondering what it would take to proxy and extend an external web services. This can be done very simple with node:

var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({
  target: 'https://$URL_FOR_SERVICE_TO_EXTEND',
  changeOrigin: true
});

require('http').createServer(function(req, res) {
  if(/* check whether we should return a different result, 
      * i.e. the url is our new endpoint */) {
    /* res."return new result"(..) */
  } else {
    proxy.web(req, res, {});
  }
}).listen(8080);

Just npm install http-proxy before starting the program, and then you can run an augmented service.

Leave a Reply

Your email address will not be published. Required fields are marked *