ufo-tech/json-rpc-client-sdk
Composer 安装命令:
composer require ufo-tech/json-rpc-client-sdk
包简介
Simple clientSDK builder for any json-RPC servers
关键字:
README 文档
README
Simple clientSDK builder for any json-RPC servers
See the Documentations
New in version 4.2
⚙️ Service parameters for UFO-json-rpc servers
Support for service-level RPC parameters has been added for servers implemented with UFO-json-rpc.
The SDK now allows request configuration via a fluent chain, without changing method signatures.
🔹 Basic call (as before)
$userService->list();
🔹 Cache control
$userService ->withoutCache() ->list();
🔹 Passing service metadata
$userService ->rayId('someRayId') ->list();
🔹 Async-specific parameters
For async procedures, additional execution control options are available:
$asyncUserService ->withCache() ->rayId('someRayId') ->timeout(30) // timeout in seconds ->callback('https://some.url/hook') // webhook callback ->list();
📌 Notes
- Service parameters are not passed as business method arguments.
- They are applied at the RPC context level and handled by the server.
- Works only with UFO-json-rpc compatible servers.
- The SDK remains type-safe — method signatures are unchanged.
New in version 4.1
🔍 Filtering methods during SDK generation
The SDK supports skipping RPC methods during generation.
This is done using the ignoredMethods option, which accepts a list of masks.
📌 Mask Rules
*— any sequence of characters!at the beginning — inversion (always generate)&at the beginning or after!— indicates a sync request~at the beginning or after!— indicates an async request- Other characters are literals, meaning they represent themselves
✔️ Example masks
| Mask | Description |
|---|---|
AdminApi.* |
ignores all methods of AdminApi class |
Command.run |
ignores only Command.run |
#Command.run |
ignores only Command.run in sync API |
*.delete |
ignores all delete() methods in any class |
!~Comment.delete |
always generates Comment.delete for async API even if *.delete blocks it |
*.*Test |
ignores all methods ending with Test |
🚫 Prohibited
| Mask | Reason |
|---|---|
User.?pdate |
? is not supported |
~&User.update |
~ and & in one mask is not supported |
[A-Z]*.create |
regex is not supported |
📎 Usage Example
$configHolder = new ConfigsHolder( docReader: new HttpReader($apiUrl), projectRootDir: getcwd(), apiVendorAlias: $vendorName, ignoredMethods: [ 'AdminApi.*', 'Command.run', '*.delete', '!Comment.delete', '*.*Test' ] );
Masks allow you to easily remove service procedures, test methods, and unwanted CRUD operations from SDK generation.
Generate SDK
Run cli command php bin/make.php
$ php bin/make.php http://some.url/api > Enter API vendor name: some_vendor > Enter methods to ignore (comma-separated) or empty: *.delete,!Comment.delete
Or
$ php bin/make.php
Use SDK
This example shows working with the generated SDK. IMPORTANT: You may have other procedure classes. The example only shows the concept of interaction.
<?php use Symfony\Component\HttpClient\CurlHttpClient; use Ufo\RpcSdk\Client\Shortener\UserProcedure; use Ufo\RpcSdk\Client\Shortener\PingProcedure; use Ufo\RpcSdk\Procedures\AbstractProcedure; require_once __DIR__ . '/../vendor/autoload.php'; $headers = [ 'Ufo-RPC-Token'=>'some_security_token' ]; try { $pingService = new PingProcedure( headers: $headers ); echo $pingService->ping(); // print "PONG" // ... $userService = new UserProcedure( headers: $headers, requestId: uniqid(), rpcVersion: AbstractProcedure::DEFAULT_RPC_VERSION, httpClient: new CurlHttpClient(), httpRequestOptions: [] ); $user = $userService->createUser( login: 'some_login', password: 'some_password' ); var_dump($user); // array(3) { // ["id"]=> int(279232969) // ["login"]=> string(3) "some_login" // ["status"]=> int(0) } catch (\Throwable $e) { echo $e->getMessage() . PHP_EOL; } // ...
Debug request and response
<?php // ... use Ufo\RpcSdk\Procedures\RequestResponseStack; // ... $fullStack = RequestResponseStack::getAll(); // get all previous requests and responses $lastStack = RequestResponseStack::getLastStack(); // get last requests and responses $lastRequest = RequestResponseStack::getLastRequest(); // get last request $lastResponse = RequestResponseStack::getLastResponse(); // get last response // ...
Profit
ufo-tech/json-rpc-client-sdk 适用场景与选型建议
ufo-tech/json-rpc-client-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.99k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rpc」 「api」 「sdk」 「async」 「json-rpc」 「Ufo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ufo-tech/json-rpc-client-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ufo-tech/json-rpc-client-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ufo-tech/json-rpc-client-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Microservice RPC through message queues.
A PSR-7 compatible library for making CRUD API endpoints
Control Nginx as a reverse proxy through plinker RPC
A API library that make it easy to access the Webuntis JSON RPC 2.0 API
rpc gateway lib
Implementation of Bitclout API interaction through its node
统计信息
- 总下载量: 2.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-18