@fmal/http-service
Version:
A HTTP service - orignally @cerebral/http
31 lines (25 loc) • 640 B
JavaScript
;
exports.__esModule = true;
exports.default = request;
function request(options, cb) {
if (options === void 0) {
options = {};
}
var xhr = new XMLHttpRequest();
xhr.addEventListener('progress', cb);
xhr.addEventListener('load', cb);
xhr.addEventListener('error', cb);
xhr.addEventListener('abort', cb);
xhr.ontimeout = function () {
var ev = {
type: 'timeout',
currentTarget: xhr
};
cb(ev);
};
xhr.open(options.method, options.baseUrl + options.url);
xhr.timeout = options.timeout || 0;
options.onRequest(xhr, options);
return xhr;
}
module.exports = exports.default;