@jcubic/json-rpc
v1.0.0
Published
Promise based JSON-RPC client with zero dependencies
Readme
@jcubic/json-rpc
Promise based JSON-RPC client with zero dependencies.
Installation
npm install @jcubic/json-rpcUsage
import rpc from '@jcubic/json-rpc';
const service = await rpc({
url: '/api/json-rpc.php'
});
const result = await service.my_method('arg1', 'arg2');The client calls system.describe on the endpoint to discover available
procedures and returns a service object with one method per procedure.
Every method returns a promise that resolves with result or rejects
with the JSON-RPC error object.
Options
url(required) — URL of the JSON-RPC endpointerror(error)— optional global error handlerdebug(data, type)— optional debug callback, invoked with the raw request/response payloads
Errors
Service methods reject with the JSON-RPC error object
({ code, message, data? }). Network and parse failures throw an
Error with a numeric code property:
300— network/parse error301— empty response from the server
Server
The matching PHP server implementation is available as the Composer
package jcubic/json-rpc.
License
Copyright (c) 2009-2026 Jakub T. Jankiewicz
Released under the MIT License. See LICENSE for details.
