// REST API client with authenticationclass ApiClient { constructor(baseURL, apiKey) { this.baseURL = baseURL; this.apiKey = apiKey; } async request(endpoint, options = {}) { const url = `${this.baseURL}${endpoint}`; const response = await fetch(url, { ...options, headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json', ...options.headers, }, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); } // GET request async getUsers() { return this.request('/users'); } // POST request async createUser(userData) { return this.request('/users', { method: 'POST', body: JSON.stringify(userData), }); }}// Usageconst client = new ApiClient('https://api.example.com', 'your-api-key');const users = await client.getUsers();console.log('Users:', users);