31 lines
711 B
JavaScript
31 lines
711 B
JavaScript
(function collonadeClosure() {
|
|
'use strict';
|
|
|
|
window.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);
|
|
},
|
|
}
|
|
})();
|
|
})();
|