UNPKG

integration-websocket-rest-api

Version:

A JavaScript library for easy integration of REST API and WebSocket communication with state management in JS applications.

25 lines (21 loc) 482 B
const axios = require("axios"); class ApiClient { constructor(apiUrl, headers = {}) { this.apiUrl = apiUrl; this.headers = headers; } async sendRequest(method, data) { try { const response = await axios({ method, url: this.apiUrl, headers: this.headers, data, }); return response.data; } catch (error) { throw new Error(`API request failed: ${error.message}`); } } } module.exports = ApiClient;