tourze/json-rpc-http-direct-call-bundle
最新稳定版本:1.1.0
Composer 安装命令:
composer require tourze/json-rpc-http-direct-call-bundle
包简介
JsonRPC另外一种调用方式
README 文档
README
A Symfony bundle that provides HTTP direct call functionality for JSON-RPC services. This bundle offers an alternative approach to JSON-RPC invocation through HTTP endpoints.
Features
- HTTP direct calls to JSON-RPC services
- Request/response encryption and decryption support
- Multiple calling interface forms
- Automatic route loading with attributes
- Built-in error handling and logging
- Support for prefixed and non-prefixed endpoints
Requirements
- PHP 8.2 or higher
- Symfony 7.3 or higher
- ext-json
Installation
composer require tourze/json-rpc-http-direct-call-bundle
Configuration
Add the bundle to your config/bundles.php file:
return [ // ... Tourze\JsonRPCHttpDirectCallBundle\JsonRPCHttpDirectCallBundle::class => ['all' => true], ];
Quick Start
Direct Call Endpoint
Send POST requests to JSON-RPC methods using these endpoints:
# With prefix POST /json-rpc/{prefix}/{method}.aspx # Without prefix (CP endpoint) POST /cp/json-rpc/{method}.aspx
Example request:
curl -X POST http://localhost/json-rpc/user/getInfo.aspx \ -H "Content-Type: application/json" \ -H "request-id: unique-request-id" \ -d '{"userId": 123}'
Direct POST Endpoint
Send POST requests directly to methods:
POST /json-rpc/call/{method}
Example request:
curl -X POST http://localhost/json-rpc/call/getUser \
-d "userId=123&includeProfile=true"
Usage
Controllers
The bundle provides two main controllers:
- DirectCallController - Handles requests to
/json-rpc/{prefix}/{method}.aspxand/cp/json-rpc/{method}.aspx - DirectPostController - Handles requests to
/json-rpc/call/{method}
Encryption Support
The bundle supports request/response encryption when the encryptor service detects encrypted endpoints:
// Automatic encryption detection based on request path if ($this->encryptor->shouldEncrypt($request)) { $decryptedContent = $this->encryptor->decryptByRequest($request, $content); // Process decrypted content... }
Request ID Handling
The bundle automatically handles request IDs:
- Uses
request-idheader if provided - Generates UUID v4 if not provided
- Prefixes with endpoint prefix for tracking
Architecture
src/
├── Controller/
│ ├── DirectCallController.php # Main JSON-RPC endpoint controller
│ └── DirectPostController.php # Direct POST endpoint controller
├── DependencyInjection/
│ └── JsonRPCHttpDirectCallExtension.php # Service configuration
├── Exception/
│ └── UnexpectedControllerException.php # Custom exceptions
├── Service/
│ └── AttributeControllerLoader.php # Route auto-loader
└── JsonRPCHttpDirectCallBundle.php # Bundle class
Testing
Run tests from the project root directory:
./vendor/bin/phpunit packages/json-rpc-http-direct-call-bundle/tests
Test coverage includes:
- Unit tests for all components
- Integration tests for complete workflows
- Mock services for dependencies
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-27