fradrive/static/js/utils/httpClient.js
2019-02-24 23:00:21 +01:00

33 lines
755 B
JavaScript

(function collonadeClosure() {
'use strict';
window.utils = window.utils || {};
window.utils.httpClient = (function() {
function _fetch(url, method, additionalHeaders, body) {
var requestOptions = {
credentials: 'same-origin',
headers: { },
method: method,
body: body,
};
Object.keys(additionalHeaders).forEach(function(headerKey) {
requestOptions.headers[headerKey] = additionalHeaders[headerKey];
});
return fetch(url, requestOptions);
}
return {
get: function(url, headers) {
return _fetch(url, 'GET', headers);
},
post: function(url, headers, body) {
return _fetch(url, 'POST', headers, body);
},
}
})();
})();