1.0.51 • Published 6 months ago

integration-websocket-rest-api v1.0.51

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

REST API, WebSocket and Redux Integration Package

This package provides a seamless integration of REST API and WebSocket functionality into your applications. It leverages the power of Redux for state management, allowing you to easily manage actions for both REST and WebSocket interactions. The package can be published to npm and installed in any compatible application, such as Angular applications. Additionally, this package includes features like reconnection logic and data formatting.

Installation

Install this package with npm

  npm install integration-websocket-rest-api

Usage/Examples

API Client

The package includes an API client (ApiClient) for making REST API requests. It uses Axios for HTTP requests and provides features like request retries, timeouts, and customizable error handling. The API client is designed to work seamlessly with Redux for state management.

import { Component, OnInit } from "@angular/core";
import { ApiClient } from "integration-websocket-rest-api";

@Component({
  selector: "app-my-component",
  templateUrl: "./my-component.component.html",
  styleUrls: ["./my-component.component.css"],
})
export class MyComponent implements OnInit {
  constructor() {}

  ngOnInit(): void {
    const apiUrl = "https://example_url.com";
    const apiClient = new ApiClient(apiUrl);

    // Set global headers if needed
    apiClient.setGlobalHeaders({
      Authorization: "Bearer YOUR_ACCESS_TOKEN",
    });
    // Make a GET request
    apiClient
      .sendRequest("GET" / "POST", null / data, "other congigurations")
      .pipe(map((messages) => console.log(messages)));
  }
}

WebSocket Client

The package also includes a WebSocket client (WebSocketClient) for real-time communication. It uses the websocket library and integrates seamlessly with Redux for managing WebSocket messages.

import { Component, OnInit } from "@angular/core";
import { WebSocketClient } from "integration-websocket-rest-api";

@Component({
  selector: "app-my-component",
  templateUrl: "./my-component.component.html",
  styleUrls: ["./my-component.component.css"],
})
export class MyComponent implements OnInit {
  constructor() {}

  ngOnInit(): void {
    const wsUrl = "wss://socket.example.com";
    const wsClient = new WebSocketClient(wsUrl);
    // Open WebSocket connection
    wsClient.openConnection();

    // Send messages
    wsClient.sendMessage(action.message);

    // Listen for incoming WebSocket messages
    this.wsClient.getMessage((message: any) => {
      console.log(`Received message: ${message}`);
    });
  }
}

State Management

The package utilizes Redux for state management. It includes actions (wsMessageReceived, apiRequestSuccess, apiRequestFailure) and reducers for handling WebSocket messages and API responses inside the package.

Configuration

Both the API client and WebSocket client support configuration options. You can customize headers, retries, timeouts, and more. Refer to the respective client files for available configuration methods.

Support

For support, email sarda2t@cmich.edu or padma1y@cmich.edu or debba1s@cmich.edu or kandu3s@cmich.edu.

1.0.51

6 months ago

1.0.50

6 months ago

1.0.49

6 months ago

1.0.48

6 months ago

1.0.47

6 months ago

1.0.46

6 months ago

1.0.45

6 months ago

1.0.44

6 months ago

1.0.43

6 months ago

1.0.42

6 months ago

1.0.41

6 months ago

1.0.39

6 months ago

1.0.38

6 months ago

1.0.37

6 months ago

1.0.36

6 months ago

1.0.35

6 months ago

1.0.34

6 months ago

1.0.33

6 months ago

1.0.32

7 months ago

1.0.31

7 months ago

1.0.30

7 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.27

7 months ago

1.0.26

7 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.20

7 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago