edgetelemetrics / php-json-rpc
JSON-RPC helper classes for PHP
v1.2.2
2025-03-16 23:21 UTC
Requires
- php: ^7.4|>=8.0
- ext-json: *
Requires (Dev)
- clue/ndjson-react: ^1.2
- evenement/evenement: ^3.0.1
Suggests
- clue/ndjson-react: Used by the React Stream Decoder to process NDJSON input
- evenement/evenement: Used by the React Stream Decoder to emit events
Provides
None
Conflicts
None
Replaces
None
README
This library contains classes to construct JSON RPC notification, request, response and error objects.
Additionally there is a ReactPHP stream decoder included which will process JSON RPC request and responses encoded via NDJSON.
https://www.jsonrpc.org/specification
Quickstart
Create a Request on the client
<?php use EdgeTelemetrics\JSON_RPC\Request; $request = new Request('ping', [], 'requestId'); $packet = json_encode($request); // Send $packet to Server
Server side
<?php //Process request // Create the response from the request to pre-fill ID $response = new Response::createFromRequest($request); $response->setResult('pong'); $packet = json_encode($response); // Send $packet back to Client