@mainframe/rpc-request
Request-based RPC
Last updated 2 years ago by paul_lecam .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mainframe/rpc-request 
SYNC missed versions from official npm registry.

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 @mainframe/rpc-request

Usage

import RequestRPC from '@mainframe/rpc-request'
import httpTransport from '@mainframe/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

Current Tags

  • 0.2.0                                ...           latest (2 years ago)

4 Versions

  • 0.2.0                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 3
Dependencies (3)
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |