@erebos/rpc-request
TypeScript icon, indicating that this package has built-in type declarations

0.11.0 • Public • Published

rpc-request

Class extending rpc-base to handle stateless JSON-RPC 2.0 calls.

See transport-create-http, transport-http-browser and transport-http-node for possible transports and rpc-stream to handle stateful JSON-RPC 2.0 calls.

Installation

yarn add @erebos/rpc-request

Usage

import RequestRPC from '@erebos/rpc-request'
import httpTransport from '@erebos/transport-http-node'

class MyAPI extends RequestRPC {
  constructor(url: string) {
    super(httpTransport(url))
  }

  getUser(id: string): Promise<{ name: string }> {
    return this.request('getUser', [id])
  }
}

const api = new MyAPI('http://my-api-url')
api.getUser('1234')

Types

type FetchFunction = <D = any, R = any>(data: D) => Promise<R>

API

See the BaseRPC API for inherited methods and properties.

new RequestRPC()

Arguments

  1. fetch: FetchFunction: function making the server call using the JSON-RPC request Object and returning the response.

.request()

Arguments

  1. method: string
  2. params: T = any

Returns Promise<R = any>

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @erebos/rpc-request

Weekly Downloads

3

Version

0.11.0

License

MIT

Unpacked Size

6.15 kB

Total Files

5

Last publish

Collaborators

  • aclarke
  • diogoperillo
  • howleysv
  • mosic
  • paul_lecam
  • sarahwiley