1broker.js
function apiRequest(url, callback) {
    var options = {
      url: url,
      method: 'GET',
			timeout: config.timeoutMS,
      maxAttempts: 3,
      retryDelay: 2000,  // (default) wait for 2s before trying again
      retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
    };

    var req = request(options, function(error, response, body) {
      if(typeof callback === 'function') {
        var data;
        if(error) {
          callback.call(self, new Error('Error in server response: ' + JSON.stringify(error)), null);
          return;
        }
        try {
          data = JSON.parse(body);
          if(data.error != false){
            callback.call(self, new Error('API error.'), null);
          } else {
            // All good.
            callback.call(self,null,data.response);
          }
        }
        catch(e) {
          callback.call(self, new Error('Could unknown server response occured.'), null);
          return;
        }
      }
    });

    return req;
  }
function apiRequest(url, callback) {
    var options = {
      url: url,
      method: 'GET',
			timeout: config.timeoutMS,
      maxAttempts: 3,
      retryDelay: 2000,  // (default) wait for 2s before trying again
      retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
    };

    var req = request(options, function(error, response, body) {
      if(typeof callback === 'function') {
        var data;
        if(error) {
          callback.call(self, new Error('Error in server response: ' + JSON.stringify(error)), null);
          return;
        }
        try {
          data = JSON.parse(body);
          if(data.error != false){
            callback.call(self, new Error('API error.'), null);
          } else {
            // All good.
            callback.call(self,null,data.response);
          }
        }
        catch(e) {
          callback.call(self, new Error('Could unknown server response occured.'), null);
          return;
        }
      }
    });

    return req;
  }
function apiRequest ( url , callback ) { var options = { url : url , method : 'GET' , timeout : config . timeoutMS , maxAttempts : 3 , retryDelay : 2000 , // (default) wait for 2s before trying again
 retryStrategy : request . RetryStrategies . HTTPOrNetworkError // (default) retry on 5xx or network errors
 } ; var req = request ( options , function ( error , response , body ) { if ( typeof callback === 'function' ) { var data ; if ( error ) { callback . call ( self , new Error ( 'Error in server response: ' + JSON . stringify ( error ) ) , null ) ; return ; } try { data = JSON . parse ( body ) ; if ( data . error != false ) { callback . call ( self , new Error ( 'API error.' ) , null ) ; } else { // All good.
 callback . call ( self , null , data . response ) ; } } catch ( e ) { callback . call ( self , new Error ( 'Could unknown server response occured.' ) , null ) ; return ; } } } ) ; return req ; }
This method sends the actual HTTP request
@param  {String}   url      The URL to make the request
@param  {String}   requestType   POST or GET
@param  {Object}   params   POST or GET body
@param  {Function} callback A callback function to call when the request is complete
@return {Object}            The request object
This method sends the actual HTTP request