UNPKG

@fmal/http-service

Version:

A HTTP service - orignally @cerebral/http

24 lines (21 loc) 550 B
export default 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; }