index.js
function _request(path, method, headers, body, withCredentials, callback) {
  const xhr = new XMLHttpRequest({});
  // Set up the event handlers.
  const handler = evt => {
    if (callback) {
      callback(evt);
    }
    // The request has been completed: detach all the handlers.
    xhr.removeEventListener('error', handler);
    xhr.removeEventListener('load', handler);
  };
  xhr.addEventListener('error', handler, false);
  xhr.addEventListener('load', handler, false);
  // Set up the request.
  xhr.open(method, path, true);
  Object.keys(headers || {}).forEach(key => {
    xhr.setRequestHeader(key, headers[key]);
  });
  if (withCredentials) {
    xhr.withCredentials = withCredentials;
  }
  xhr.send(body || undefined);
  return xhr;
}
function _request(path, method, headers, body, withCredentials, callback) {
  const xhr = new XMLHttpRequest({});
  // Set up the event handlers.
  const handler = evt => {
    if (callback) {
      callback(evt);
    }
    // The request has been completed: detach all the handlers.
    xhr.removeEventListener('error', handler);
    xhr.removeEventListener('load', handler);
  };
  xhr.addEventListener('error', handler, false);
  xhr.addEventListener('load', handler, false);
  // Set up the request.
  xhr.open(method, path, true);
  Object.keys(headers || {}).forEach(key => {
    xhr.setRequestHeader(key, headers[key]);
  });
  if (withCredentials) {
    xhr.withCredentials = withCredentials;
  }
  xhr.send(body || undefined);
  return xhr;
}
Create, set up and send an asynchronous request to the given path/URL with
the given method and parameters.

@param {String} path The remote target path/URL.
@param {String} method The request method (e.g. "GET" or "POST").
@param {Object} headers Additional request headers as key/value pairs.
@param {Object} body The data to send as a file object, a string or in
general as an ArrayBufferView/Blob object.
@param {Boolean} withCredentials Whether to include credentials.
@param {Function} callback The load event callback.
@return {Object} The xhr asynchronous request instance.