v-jsonrpc-test
v1.0.0
Published
A TypeScript library implementing JSON-RPC client
Maintainers
Readme
v-jsonrpc-test
A TypeScript library implementing JSON-RPC client functionality.
Installation
npm install v-jsonrpc-test
# or
yarn add v-jsonrpc-testFeatures
- JSON-RPC Client: Implementation of a JSON-RPC client
- Type Safety: Full TypeScript support with type definitions
- Compatibility: Works with both browser and Node.js environments
- Streaming: Built on top of xstream for reactive programming
Usage
import { JsonRpcClient, SimpleMessagingConnection } from 'v-jsonrpc-test';
import { Stream } from 'xstream';
// Create a simple messaging connection
const connection: SimpleMessagingConnection = {
responseStream: Stream.create(),
send: (request) => {
// Send the request to your server
fetch('https://your-api.com/rpc', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(request)
})
.then(response => response.json())
.then(data => {
// Push the response to the stream
connection.responseStream._producer.next(data);
});
}
};
// Create a JSON-RPC client
const client = new JsonRpcClient(connection);
// Make a request
client.request('add', [1, 2])
.then(result => {
console.log('Result:', result); // 3
})
.catch(error => {
console.error('Error:', error);
});Dependencies
- xstream: ^11.14.0
- v-stream-test: ^1.0.0
License
ISC
