Registry / messaging / integration-websocket-rest-api

integration-websocket-rest-api

JSON →
library1.0.51jsnpmunverified

Version 1.0.51. This package integrates REST API and WebSocket communication with Redux-based state management for JavaScript applications, targeting Angular and other frameworks. It provides ApiClient (backed by Axios) with retries, timeouts, and custom error handling, and a WebSocketClient with reconnection logic. Unlike standalone HTTP or WebSocket libraries, it automatically dispatches Redux actions (wsMessageReceived, apiRequestSuccess, apiRequestFailure) and includes TypeScript definitions. However, the documentation is sparse and the version patch number suggests ongoing maintenance; it is not widely adopted.

npm install integration-websocket-rest-api
INSTALL
IMPORT
SIG · INTEGRATION-WEBSOC
I
integration-websocket-rest-api
messagingjavascriptv1.0.51
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ApiClient
import { ApiClient } from 'integration-websocket-rest-api'
import ApiClient from 'integration-websocket-rest-api'
This is a named export. Using default import will result in undefined at runtime.
WebSocketClient
import { WebSocketClient } from 'integration-websocket-rest-api'
const WebSocketClient = require('integration-websocket-rest-api').WebSocketClient
The package ships TypeScript types and is ESM-first. CJS require may work but is not officially supported.
wsMessageReceived
import { wsMessageReceived } from 'integration-websocket-rest-api'
Named export for the Redux action creator. Use it directly in dispatch calls.
apiRequestSuccess
import { apiRequestSuccess } from 'integration-websocket-rest-api'
Named export for the Redux action creator. Use it in reducers or dispatching after API calls.
apiRequestFailure
import { apiRequestFailure } from 'integration-websocket-rest-api'
Named export for the Redux action creator. Handles error states.

This example shows how to import ApiClient and WebSocketClient, configure them, and wire up Redux actions for state management.

import { ApiClient, WebSocketClient, wsMessageReceived, apiRequestSuccess, apiRequestFailure } from 'integration-websocket-rest-api'; import { createStore } from 'redux'; // Setup Redux store with a simple reducer const initialState = { messages: [], apiData: null, error: null }; const reducer = (state = initialState, action) => { switch(action.type) { case 'WS_MESSAGE_RECEIVED': return { ...state, messages: [...state.messages, action.payload] }; case 'API_REQUEST_SUCCESS': return { ...state, apiData: action.payload }; case 'API_REQUEST_FAILURE': return { ...state, error: action.payload }; default: return state; } }; const store = createStore(reducer); // Use ApiClient const apiClient = new ApiClient('https://api.example.com'); apiClient.setGlobalHeaders({ Authorization: 'Bearer ' + (process.env.API_TOKEN ?? '') }); apiClient.sendRequest('GET', '/data', { timeout: 5000 }).subscribe( (data) => store.dispatch(apiRequestSuccess(data)), (err) => store.dispatch(apiRequestFailure(err.message)) ); // Use WebSocketClient const wsClient = new WebSocketClient('wss://ws.example.com'); wsClient.openConnection(); wsClient.getMessage((message) => { store.dispatch(wsMessageReceived(message)); }); wsClient.sendMessage({ type: 'subscribe', channel: 'updates' });
Debug
Known issues
gotchaThe sendRequest method's first parameter is a string combining HTTP method and URL path, e.g., 'GET /data'. The README shows incorrect syntax: "GET" / "POST", null / data, "other congigurations". Actual usage expects three arguments: method (string), data (any), config (object).
fix
Use: apiClient.sendRequest('GET', null, { url: '/data', timeout: 5000 }) or check the source for exact signature.
affects: <=1.0.51
gotchaWebSocketClient.getMessage method expects a callback argument. If you forget to pass a callback, no error is thrown but messages are silently dropped.
fix
Always provide a callback: wsClient.getMessage((msg) => console.log(msg));
affects: >=1.0.0
gotchaThe package uses RxJS but does not re-export it; you must install rxjs separately. Missing dependency causes runtime error 'Rx is not defined'.
fix
Install rxjs: npm install rxjs
affects: >=1.0.0
gotchaRedux actions are dispatched internally but the package does not automatically connect to your store. You must manually dispatch actions or configure middleware. If you do not dispatch, state remains unchanged.
fix
After receiving data from ApiClient/WebSocketClient, dispatch the appropriate action creator.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'integration-websocket-rest-api' or its corresponding type declarations.
Package not installed or TypeScript cannot resolve types (types are included but may not be picked up automatically).
fix
Install the package: npm install integration-websocket-rest-api. If types still missing, add 'integration-websocket-rest-api' to tsconfig.json types array or create a declaration file.
TypeError: apiClient.sendRequest is not a function
Importing ApiClient incorrectly (default import vs named import).
fix
Change import to: import { ApiClient } from 'integration-websocket-rest-api';
Uncaught ReferenceError: Rx is not defined
RxJS is a peer dependency and not installed automatically.
fix
Install rxjs: npm install rxjs
Upgrade
Version history
1.0.51latest on npm
Audit
Dependencies
axiosrequiredUsed for HTTP requests in ApiClient
reduxrequiredRequired for state management and action dispatching
rxjsrequiredUsed internally for observables (e.g., API calls return Observables)
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
integration-websocket-rest-api — npm install integration-websocket-rest-api · libregistry