const API_BASE_URL = 'https://api.example.com';
async function apiRequest(path, options = {}) {
const response = await fetch(`${API_BASE_URL}${path}`, {
method: options.method ?? 'GET',
headers: {
'Content-Type': 'application/json',
...(options.headers ?? {}),
},
body: options.body ? JSON.stringify(options.body) : undefined,
});
if (!response.ok) {
throw new Error(`HTTP ${response.status} for ${path}`);
}
return response.json();
}
async function loadProfile() {
return apiRequest('/profile');
}
const API_BASE_URL = 'https://api.example.com';
async function apiRequest(path, options = {}) {
const response = await fetch(`${API_BASE_URL}${path}`, {
method: options.method ?? 'GET',
headers: {
'Content-Type': 'application/json',
...(options.headers ?? {}),
},
body: options.body ? JSON.stringify(options.body) : undefined,
});
if (!response.ok) {
throw new Error(`HTTP ${response.status} for ${path}`);
}
return response.json();
}
async function loadProfile() {
return apiRequest('/profile');
}