edgetelemetrics / php-json-rpc
PHP 的 JSON-RPC 辅助类
v1.2.1
2024-02-28 04:35 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
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