@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
40 lines • 972 B
JavaScript
// src/ApiClient.ts
var ApiClient = class _ApiClient {
baseUrl;
headers;
options;
static _default;
constructor(baseUrl = "", options = {}) {
this.baseUrl = baseUrl;
this.options = options;
this.headers = new Headers({
Accept: "application/json",
"Content-Type": "application/json",
...this.options.headers
});
}
request = async (method, endpoint, data = {}) => {
const response = await fetch(`${this.baseUrl}/${endpoint}`, {
...this.options,
headers: this.headers,
mode: "cors",
method,
body: ["POST", "PUT"].includes(method) ? JSON.stringify(data) : void 0
});
const json = await response.json();
return json;
};
static get default() {
if (!_ApiClient._default) {
_ApiClient._default = new _ApiClient();
}
return _ApiClient._default;
}
get default() {
return _ApiClient.default;
}
};
export {
ApiClient
};
//# sourceMappingURL=ApiClient.js.map