Connect to any API with confidence

JSapi-client.js
1// REST API client with authentication2class ApiClient {3  constructor(baseURL, apiKey) {4    this.baseURL = baseURL;5    this.apiKey = apiKey;6  }7 8  async request(endpoint, options = {}) {9    const url = this.baseURL + endpoint;10    const response = await fetch(url, {11      ...options,12      headers: {13        'Authorization': 'Bearer ' + this.apiKey,14        'Content-Type': 'application/json',15        ...options.headers,16      },17    });18 19    if (!response.ok) throw new Error('HTTP error');20    return response.json();21  }22}