edgetelemetrics/php-json-rpc

JSON-RPC helper classes for PHP

v1.2.1 2024-02-28 04:35 UTC

This package is auto-updated.

Last update: 2024-04-28 05:07:44 UTC


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