import { JSONRPCClient } from "https://dotland.deno.dev/x/json_rpc_ts@v0.2.0/mod.ts";
Provide a external requestForResponse
function to the constructor,
it should accept a string
(json encoded from one or more json rpc request)
and your customized function should send this string to a json rpc server
for any response represented as string
The constructor optionally accept a customized id generator, otherwise it use a self added number
To customize the request or response, you can extend JSONRPCClient
.
To customize request, overwrite createRequest
and createNotification
methods.
To customize response, overwrite request
notify
and batch
methods.
Constructors
Type Parameters
Methods
You should use the createRequest()
or createNotification()
method to
create the requests array. Response order is always matched by id.
Throws JSONRPCClientParseError
if server response cannot be parsed,
note that it does not throws for any JSONRPCErrorResponse
, in this
case it will be a single object: { status: 'rejected', reason: {...} }
Usually it returns be like (same as the Promise.allSettled()
method):
[
{ status: 'fulfilled', value: '...' },
{
status: 'rejected',
reason: {
code: -32601,
message: 'Method not found',
},
},
]