edgetelemetrics/php-json-rpc

PHP 的 JSON-RPC 辅助类

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

This package is auto-updated.

Last update: 2024-09-28 06:11:00 UTC


README

此库包含用于构建 JSON-RPC 通知、请求、响应和错误对象的类。

此外,还包括一个 ReactPHP 流解码器,可以处理通过 NDJSON 编码的 JSON-RPC 请求和响应。

https://www.jsonrpc.org/specification

快速入门

在客户端创建请求

<?php
use EdgeTelemetrics\JSON_RPC\Request;
$request = new Request('ping', [], 'requestId');

$packet = json_encode($request);

// Send $packet to Server

服务器端

<?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