萨贾亚 / client
JSON-RPC 2.0 的客户端和服务器
1.2.0
2024-03-15 23:46 UTC
Requires
- guzzlehttp/guzzle: ^7.4
- illuminate/http: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: 8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0
- sajya/server: ^5.2|^6.0
README
此软件包允许您通过 HTTP(S) 设置 JSON-RPC 客户端,使用您的 PHP 代码发起请求。它基于 Laravel(不需要整个框架,只需其组件)的表达式 HTTP 包装器构建,允许您自定义授权、重试等。
安装
进入项目目录,运行以下命令
$ composer require sajya/client
使用方法
use Illuminate\Support\Facades\Http; use Sajya\Client\Client; $client = new Client(Http::baseUrl('http://localhost:8000/api/v1/endpoint')); $response = $client->execute('tennis@ping'); $response->result(); // pong
默认情况下,请求标识符将使用 UUID 生成,您可以通过调用 id()
方法来获取它
$response->id();
要获取错误结果,需要调用 error()
方法
$response->error();
参数
位置参数示例
$response = $client->execute('tennis@ping', [3, 5]);
命名参数示例
$response = $client->execute('tennis@ping', ['end' => 10, 'start' => 1]);
批量请求
在单个 HTTP 请求中调用多个过程
$batchData = $client->batch(function (Client $client) { $client->execute('tennis@ping'); $client->execute('tennis@ping'); });
通知请求
$client->notify('procedure@method');
许可协议
MIT 许可协议 (MIT)。请参阅 许可文件 获取更多信息。