xujif/guzzle-json-rpc

基于 Guzzle 的 json-rpc 服务器和客户端,支持异步

1.0.4 2017-05-04 07:06 UTC

This package is auto-updated.

Last update: 2024-08-27 20:19:54 UTC


README

# 基于 Guzzle 的 json-rpc 完整的 json-rpc 2.0 RFC 实现

### 使用 #### 服务器

/*
 * in any http framworks
 */
$apiObject = new Api();
$server = new \Xujif\JsonRpc\Server($apiObject);
// return array
// please return to client with json
$ret = $server->handle();
header('Content-Type:application/json')
echo json_encode($ret);

#### 客户端

$client = new \Xujif\JsonRpc\Client('API_SERVER_URL');
$client->call('method',[1,2,3]);
// or
$client->method(1,2,3)
// or notification(no result send async)
$client->notify()->method(1,2,3)
// or batch call
$client->batch()->method(1,2,3)->method2(1,2)->exec();
// or batch notification
$client->batch()->notify()->method(1,2,3)->method2(1,2)->exec();
// or batch mixed notification and call
// if all batch call is notify it will send async
$client->batch()
       ->notify()
       ->method(1,2,3)
       ->notify(false)
       ->method2(1,2)
       ->exec();