New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@therms/rpc-client

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@therms/rpc-client

RPC framework, browser client lib

  • 1.0.3
  • npm
  • Socket score

Version published
Weekly downloads
46
decreased by-75.14%
Maintainers
2
Weekly downloads
 
Created
Source

@therms/rpc-client

A Remote Procedure Call framework for Javascript environments (Node.js & Browser).

npm i @therms/rpc-client

Client

Basic Usage

import { RPCClient } from '@therms/rpc-client'

/* Create a client instance */
const rpc = new RPCClient({
  hosts: {
    http: 'http://localhost:3995/rpc',
    websocket: 'ws://localhost:3996', // optional
  },
});

/* Make a remote procedure call */
const {
  code, // http status code, ie: 200
  data, // any data returned from the remote/server
  message, // a human readable message from the remote/server
  success, // boolean, true|false if the procedure was succesful
} = await rpc.call({
  // optional
  args: {
    email: 'me@gmail.com',
    password: '1234567',
  },
  procedure: 'login',
  // optional
  scope: 'auth',
  // optional
  version: '1',
});

Advanced Usage

Create a client instance w/ cache and call deadline/timeout
const rpc = new RPCClient({
  cacheMaxAgeMs: 5 * 60 * 1000, // optional
  deadlineMs: 5000, // optional
  hosts: {
    http: 'localhost:3995/rpc',
  },
});
Create request interceptor
const rpc = new RPCClient({
  hosts: {
    http: 'localhost:3995/rpc',
  },
  requestInterceptor: (request) => {
    request.args.count = request.args.count + 1;

    return request;
  },
});

const { data } = await rpc.call({
  args: { count: 1 },
  procedure: 'intercept-request',
});

console.log(data.count); // => 2
Create response interceptor
const rpc = new RPCClient({
  hosts: {
    http: 'localhost:3995/rpc',
  },
  responseInterceptor: (response) => {
    response.data.count = 100;

    return response;
  },
});

const { data } = await rpc.call({
  args: { count: 1 },
  procedure: 'intercept-request',
});

console.log(data.count); // => 100
Create a client instance w/ custom transports

First, setup a custom Transport:

see the required interface in src/client/Transports/Transport.ts

class CustomHTTPTransport {
  isConnected() {
    return true;
  }

  name: 'CustomHTTPTransport';

  async sendRequest(call) {
    const response = await fetch('localhost:3901/rpc', {
      data: call,
    }).then((res) => res.json());

    return response;
  }

  setIdentity(identity) {
    this.identity = identity;
  }
}

Then, use the CustomHTTPTransport when you create a client instance:

const rpc = new RPCClient({
  cacheMaxAgeMs: 5 * 60 * 1000, // optional
  deadlineMs: 5000, // optional
  transports: {
    http: new CustomHTTPTransport(),
  },
});

FAQs

Package last updated on 01 Apr 2021

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