承接 janderson/json-rpc 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

janderson/json-rpc

最新稳定版本:v0.1

Composer 安装命令:

composer require janderson/json-rpc

包简介

Minimal JSON-RPC 2.0 implementation

README 文档

README

A library implementing the JSON-RPC 2.0 specification. Another one.

Usage

Server

On the server, a request should be read to ensure validity, dispatched, and a response produced.

use Janderson\JsonRpc;

$json = '{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}';
$request = JsonRpc\Request::parse($json); // or ::read($object) with a parsed object or array

$response = is_array($request)
    ? array_filter(array_map(dispatch(...), $request))
    : dispatch($request);
    
echo json_encode($response);

function dispatch(JsonRpc\Request|JsonRpc\Response $request): JsonRpc\Response|null
{
    // Request error directly produces an error response
    if ($request->isError()) {
        return $request;
    }
    
    try {
        $result = call_your_function_of_choice($request->method, ...$request->params);
        return JsonRpc\Response::fromResult($result, $request); // Response (result) subtype
    } catch (\Exception $e) {
        return JsonRpc\Response::fromThrowable($e, $request); // Error subtype
    }
}

Client

The client should only have to build a request and handle the response.

use Janderson\JsonRpc;

$request = JsonRpc\Request::request('subtract', [2, 1]);
$response = JsonRpc\Response::parse($client->send($request)); // HTTP client, or some other transport
if ($response->isError()) {
    throw new Exception($response->error->message, $response->error->code);
}
echo "Result is {$response->result}\n";

Structure

The structure of the library's classes attempts to follow the JSON-RPC 2.0 specification as closely as possible.

  • Request and Response are the main classes for requests and responses
  • Request has subtypes Request\Request and Request\Response
  • Response has subtypes Response\Response and Response\Error
  • The error field in Response\Error has its own type: Response\Error\Error

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固