25 lines
583 B
JavaScript
25 lines
583 B
JavaScript
/**
|
|
* Make HTTP request to API
|
|
*/
|
|
export async function requestApi(method, url, authToken, body) {
|
|
const headers = {
|
|
'Content-Type': 'application/json',
|
|
};
|
|
if (authToken) {
|
|
headers['Authorization'] = `Bearer ${authToken}`;
|
|
}
|
|
const options = {
|
|
method,
|
|
headers,
|
|
};
|
|
if (body) {
|
|
options.body = body;
|
|
}
|
|
const response = await fetch(url, options);
|
|
const responseBody = await response.text();
|
|
return {
|
|
status: response.status,
|
|
body: responseBody,
|
|
};
|
|
}
|
|
//# sourceMappingURL=http.js.map
|