UNPKG

@xsfish/uberduck

Version:
25 lines (24 loc) 721 B
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();