Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imean-service-client

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imean-service-client

Universal client for @imean/service-engine

  • 1.3.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
215
increased by90.27%
Maintainers
0
Weekly downloads
 
Created
Source

@imean/service-client

Universal TypeScript client for @imean/service-engine, supporting both HTTP and WebSocket protocols.

Features

  • 🔄 Automatic WebSocket reconnection
  • 📡 Streaming support
  • 🔁 Retry mechanism
  • ⚡ Request interceptors
  • 🚦 Request queue management
  • 💪 Type-safe API
  • 🌐 Cross-platform (Node.js, Deno, Browser)

Installation

npm install imean-service-client

Usage

Basic Usage

import { MicroserviceClient } from "imean-service-client";

const client = new MicroserviceClient({
  baseUrl: "http://localhost:3000",
  prefix: "/api",
});

// Normal request
const result = await client.someModule.someMethod("arg1", "arg2");

// Stream request
for await (const item of await client.someModule.streamMethod(10)) {
  console.log(item);
}

WebSocket Support

const client = new MicroserviceClient({
  baseUrl: "http://localhost:3000",
  prefix: "/api",
  websocket: true, // or { timeout: 5000, retryInterval: 1000 }
});

Interceptors

const client = new MicroserviceClient({
  baseUrl: "http://localhost:3000",
  prefix: "/api",
  interceptors: [
    {
      onRequest: async (config) => {
        config.headers["Authorization"] = "Bearer token";
      },
      onResponse: async (response) => {
        // Transform response
        return response;
      },
      onError: async (error) => {
        // Handle error
        return error;
      },
    },
  ],
});

Retry Configuration

const client = new MicroserviceClient({
  baseUrl: "http://localhost:3000",
  prefix: "/api",
  retry: {
    maxAttempts: 3,
    delays: [1000, 2000, 5000],
    shouldRetry: (error) => error instanceof ConnectionError,
  },
});

Request Queue

const client = new MicroserviceClient({
  baseUrl: "http://localhost:3000",
  prefix: "/api",
  request: {
    concurrency: 5, // Maximum concurrent requests
    timeout: 5000,
  },
});

API Reference

MicroserviceClient

Constructor Options
interface ClientConfig {
  baseUrl: string;
  prefix?: string;
  headers?: Record<string, string>;
  fetch?: typeof fetch;
  websocket?: boolean | Partial<WebSocketOptions>;
  retry?: RetryOptions;
  request?: RequestOptions;
  stream?: StreamOptions;
  interceptors?: RequestInterceptor[];
}
WebSocket Options
interface WebSocketOptions {
  url: string;
  timeout?: number;
  retryInterval?: number;
  maxRetries?: number;
  pingInterval?: number;
  WebSocket?: typeof WebSocket;
  onClose?: () => void;
  onError?: (error: Error) => void;
  onReconnect?: () => void;
  onReconnected?: () => void;
}

For more details, please check the source code and tests.

License

MIT

Keywords

FAQs

Package last updated on 02 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc