@wwog/json_rpc
v1.0.2
Published
A JSON-RPC library
Downloads
8
Maintainers
Readme
JsonRpc
import { JsonRpcBuilder, CounterIdGenerator } from "@wwog/jsonRpc";
// or
import JsonRpcBuilder, { CounterIdGenerator } from "@wwog/jsonRpc";
//If you need id generation, instantiate it, otherwise use static methods
const builder = new JsonRpcBuilder();
builder.createRequest();
//or
JsonRpcBuilder.createRequest();Type Definitions:
- Defines the core types for JSON-RPC 2.0:
JsonRpcVersion,JsonRpcId,JsonRpcError,JsonRpcRequest, andJsonRpcResponse. - Uses TypeScript interfaces and type aliases to ensure type safety.
- Defines the core types for JSON-RPC 2.0:
Features:
createRequest: Creates requests or notifications, supports parameters as arrays or objects, noidin notification mode.createSuccessResponse: Creates successful responses, including results and correspondingid.createErrorResponse: Creates custom error responses, supporting error codes, messages, and additional data.createStandardError: Creates standard error responses using error codes defined in the specification.- Built-in 4 types of
IdGenerator.
Error Handling:
- Implements standard error codes from the JSON-RPC 2.0 specification (e.g.,
-32700for parse errors). - Supports custom error data fields.
- Implements standard error codes from the JSON-RPC 2.0 specification (e.g.,
Notes
- This implementation strictly follows the JSON-RPC 2.0 specification to ensure compatibility.
- The type system ensures the structural correctness of requests and responses.
- Built-in 4 types of ID generators, with UUIdV4 used by default for ID construction.
