tourze / json-rpc-http-endpoint-bundle
JsonRPC HTTP入口模块
Installs: 75
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/json-rpc-http-endpoint-bundle
Requires
- php: ^8.1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/routing: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/backtrace-helper: 0.1.*
- tourze/bundle-dependency: 0.0.*
- tourze/json-rpc-endpoint-bundle: 0.1.*
- tourze/symfony-routing-auto-loader-bundle: 0.0.*
- willdurand/jsonp-callback-validator: ^2.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
README
[
]
(https://github.com/tourze/php-monorepo/actions)
[
]
(https://codecov.io/gh/tourze/php-monorepo)
A Symfony bundle that provides HTTP endpoints for JSON-RPC services. This bundle creates HTTP controllers that expose JSON-RPC endpoints with support for POST, GET, and OPTIONS methods, as well as JSONP callbacks.
Installation
composer require tourze/json-rpc-http-endpoint-bundle
Quick Start
- Add the bundle to your
config/bundles.php:
<?php return [ // ... other bundles Tourze\JsonRPCHttpEndpointBundle\JsonRPCHttpEndpointBundle::class => ['all' => true], ];
- The bundle automatically registers HTTP endpoints for JSON-RPC:
POST /json-rpc- Main JSON-RPC endpointGET /json-rpc- GET method with__payloadparameterOPTIONS /json-rpc- CORS preflight support
Features
- Multiple HTTP Methods: Supports POST, GET, and OPTIONS requests
- JSONP Support: GET requests support JSONP callbacks
- CORS Support: Built-in CORS headers for cross-origin requests
- Legacy Routes: Backward compatibility with existing API endpoints
- Automatic Service Discovery: Uses attribute-based controller loading
Usage
POST Requests
Send JSON-RPC requests via POST:
curl -X POST http://your-app.com/json-rpc \ -H "Content-Type: application/json" \ -d '{"jsonrpc": "2.0", "method": "your.method", "params": {"param1": "value1"}, "id": 1}'
GET Requests
Send JSON-RPC requests via GET with __payload parameter:
curl "http://your-app.com/json-rpc?__payload=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22your.method%22%2C%22params%22%3A%7B%22param1%22%3A%22value1%22%7D%2C%22id%22%3A1%7D"
JSONP Support
For JSONP requests, add a callback parameter:
curl "http://your-app.com/json-rpc?callback=myCallback&__payload=%7B...%7D"
Configuration
The bundle works with the JSON-RPC endpoint system and requires the following dependencies:
tourze/json-rpc-endpoint-bundle- Core JSON-RPC endpoint functionalitytourze/json-rpc-core- JSON-RPC protocol implementation
Available Routes
| Method | Path | Name | Description |
|---|---|---|---|
| POST | /json-rpc |
json_rpc_http_server_endpoint |
Main JSON-RPC endpoint |
| POST | /server/json-rpc |
json_rpc_http_server_endpoint__legacy-1 |
Legacy endpoint |
| GET | /json-rpc |
json_rpc_http_server_endpoint_get |
GET method endpoint |
| GET | /api/json-rpc |
json_rpc_http_api_endpoint_legacy |
Legacy GET endpoint |
| OPTIONS | /json-rpc |
- | CORS preflight support |
License
This package is licensed under the MIT License. See the LICENSE file for details.