'use strict';

var Promise = require('es6-promise').Promise;

module.exports = function request(url) {
  return new Promise(function (resolve, reject) {
    var req = new XMLHttpRequest();
    req.open('GET', url, true);

    req.onload = function () {
      resolve({ data: req.responseText });
    }

    req.onerror = reject;

    req.send();
  });
}

'use strict';

var Promise = require('es6-promise').Promise;

module.exports = function request(url) {
  return new Promise(function (resolve, reject) {
    var req = new XMLHttpRequest();
    var protocol = url.split(':').shift().toLowerCase();
    if (protocol !== 'https' && protocol !== 'http') {
      throw new Error('Unsupported protocol (' + protocol + ')');
    }

    req.open('GET', url, true);

    req.onload = function () {
      resolve({ data: req.responseText });
    }

    req.onerror = reject;

    req.send();
  });
}

Make `request()` reject unsupported protocols in the browser