Socket
Socket
Sign inDemoInstall

tsrpc-browser

Package Overview
Dependencies
11
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tsrpc-browser

TSRPC Client for browser


Version published
Maintainers
1
Install size
1.83 MB
Created

Changelog

Source

[3.4.16] - 2024-05-05

Fixed

  • Update dependencies tsbuffer

Readme

Source

Browser Client of TSRPC

TSRPC is a TypeScript RPC framework with runtime type checking and binary serialization. See more detail at https://github.com/k8w/tsrpc.

Official site: https://tsrpc.cn

Introduction

HttpClient is using XMLHttpRequest, and WebSocketClient is using WebSocket of browser. Platform adapted to XMLHttpRequest and WebSocket (like ReactNative) can also use this library.

Usage

import { HttpClient } from 'tsrpc-browser';
import { serviceProto } from './shared/protocols/serviceProto';

// Create the Client
let client = new HttpClient(serviceProto, {
    server: 'http://127.0.0.1:3000',
    logger: console
});

async function yourFunc() {
    // Call API
    let ret = await client.callApi('Hello', {
        name: 'World'
    });

    // Error: ret.err is TsrpcError
    if (!ret.isSucc) {
        alert('Error: ' + ret.err.message);
        return;
    }

    // Success: ret.res is ResHello
    alert('Success: ' + ret.res.reply);
}

Browser Support

The library is compiled to target ES2015, so if you need legacy browser support, you can use Babel to transform the final code to ES5. After that it can support all these browser:

  • IE8+
  • Chrome
  • Firefox
  • Safari
  • etc...

Caution

  1. To support Internet Explorer, you should import es6-promise polyfill by yourself.
  2. WebSocket only support IE10+.

Keywords

FAQs

Last updated on 04 May 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc