@memori.ai/memori-api-client
Version:
React library to integrate a Memori in your app or website
31 lines • 1.41 kB
JavaScript
import { default as fetch } from 'cross-fetch';
export const apiFetcher = (path, opts) => fetch(`${opts.apiUrl}${path}`, {
...opts,
body: (opts === null || opts === void 0 ? void 0 : opts.body) ? JSON.stringify(opts.body) : undefined,
mode: 'cors',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
...opts === null || opts === void 0 ? void 0 : opts.headers,
},
}).then(res => ((opts === null || opts === void 0 ? void 0 : opts.text) ? res.text() : res.json()));
export const apiBinaryFetcher = async (path, opts) => {
const responseType = (opts === null || opts === void 0 ? void 0 : opts.responseType) || 'arrayBuffer';
return fetch(`${opts.apiUrl}${path}`, {
method: opts.method || 'GET',
body: (opts === null || opts === void 0 ? void 0 : opts.body) ? JSON.stringify(opts.body) : undefined,
mode: 'cors',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
Accept: 'application/octet-stream, application/zip',
...opts === null || opts === void 0 ? void 0 : opts.headers,
},
}).then(async (res) => {
if (!res.ok) {
throw new Error(`API responded with status: ${res.status}`);
}
return responseType === 'blob' ? res.blob() : res.arrayBuffer();
});
};
//# sourceMappingURL=apiFetcher.js.map