@xsfish/uberduck
Version:
Uberduck's REST API for web client
25 lines (24 loc) • 721 B
JavaScript
export class Http {
async get(url, options) {
const headers = this._makeHeader(options);
return fetch(url, { headers }).then((res) => res.json());
}
async post(url, payload, options) {
const headers = this._makeHeader(options);
return fetch(url, {
body: JSON.stringify(payload),
headers,
method: "POST",
}).then((res) => res.json());
}
_makeHeader(options) {
let headers = {
"content-type": "application/json",
};
if (options?.basicAuthToken) {
headers["Authorization"] = `Basic ${options?.basicAuthToken}`;
}
return headers;
}
}
export default new Http();