0.1.0 • Published 4 years ago

@modfin/mf-json-rpc v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

MF JSON RPC

Install

npm i @modfin/mf-json-rpc

Call (standard request/response)

import { Rpc } from '@modfin/mf-json-rpc'

const client = new Rpc({ uri: 'ws://localhost:7357' })
// (don't need to wait for any connection to be established, it's handled internally)
const res = await client.call('method', { optional: 'params' })

Stream

TODO: maybe expose a generator or some fancy cycle.js stream, but is a simple callback for now

import { Rpc } from '@modfin/mf-json-rpc'

const client = new Rpc({ uri: 'ws://localhost:7357' })
let updates = []
client.stream('method_with_stream_support', { optional: 'params' }, update => {
    updates = [...updates, update]
})

Options

const client = new Rpc({ uri: 'ws://localhost:7357' })
const res = await client.call(
    'method',
    { optional: 'params' },
    { headers: { Authorization: authToken } }
)
client.stream(
    'method_with_stream_support',
    { optional: 'params' },
    update => { updates = [...updates, update] },
    { headers: { Authorization: authToken } }
)

Typescript support

Some methods have a template parameter to indicate the expected shape of e.g. a result:

interface ComplexType { s: string, n: number, nested: { a: (number | string)[] } }
const complexResponse: MFJsonRpcResponse<ComplexType> = await client.call<ComplexType>('complex-method')
const complexResult: ComplexType = complexResponse.result
0.1.0

4 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago