npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

integration-websocket-rest-api

v1.0.51

Published

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

Downloads

105

Readme

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 [email protected] or [email protected] or [email protected] or [email protected].