You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Symfony JSON-RPC HTTP Server to convert an HTTP json-rpc request into HTTP json-rpc response
10
+
Symfony JSON-RPC HTTP Server to convert an HTTP json-rpc request into HTTP json-rpc response.
11
+
12
+
Symfony bundle for [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk)
13
+
14
+
See [yoanm/symfony-jsonrpc-params-validator](https://github.com/yoanm/symfony-jsonrpc-params-validator) for params validation.
15
+
16
+
See [yoanm/symfony-jsonrpc-http-server-doc](https://github.com/yoanm/symfony-jsonrpc-http-server-doc) for documentation generation.
11
17
12
18
## How to use
13
19
14
-
You can either use this library as a simple extension or like any symfony bundle.
20
+
Once configured, your project is ready to handle HTTP `POST` request on `/json-rpc` endpoint.
15
21
16
-
*[Behat demo app configuration folders](./features/demo_app/) can be used as examples.*
22
+
See below how to configure it.
17
23
18
-
### With Symfony bundle
24
+
## Configuration
25
+
26
+
Bundle requires only one thing :
27
+
- JSON-RPC Methods which are compatible with [`yoanm/jsonrpc-server-sdk`](https://raw.githubusercontent.com/yoanm/php-jsonrpc-server-sdk)
28
+
29
+
It comes with [built-in method resolver](./src/Resolver/MethodResolver.php) which use a [service locator](https://symfony.com/doc/3.4/service_container/service_subscribers_locators.html#defining-a-service-locator). Using a service locator allow to load (and so instanciate dependencies, dependencies of dependencies, etc) method only when required (usually only one method is required by request, except for batch requests which will load one or more methods).
30
+
31
+
*[Behat demo app configuration folders](./features/demo_app/) can be used as examples.*
19
32
20
33
- Add the bundles in your `config/bundles.php` file:
# Or the following in case you want to customize endpoint path
59
+
#json_rpc_http_server:
60
+
# endpoint: '/my-custom-endpoint' # Default to '/json-rpc'
147
61
```
148
-
149
-
## Custom method resolver
150
62
151
-
By default this bundle use [`yoanm/jsonrpc-server-sdk-psr11-resolver`](https://github.com/yoanm/php-jsonrpc-server-sdk-psr11-resolver).
63
+
### JSON-RPC Method mapping
64
+
In order to inject yours JSON-RPC method into the server add the tag `json_rpc_http_server.jsonrpc_method` and the key/value `method` like following example :
In case you want to use your own, you can do it by using :
74
+
### Methods mapping aware
75
+
In case you want to be aware of which methods are registered inside the JSON-RPC server, you can use the `json_rpc_http_server.method_aware`. Your class must implements `JsonRpcMethodAwareInterface`.
76
+
77
+
```php
78
+
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodAwareInterface;
79
+
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
80
+
81
+
class MappingCollector implements JsonRpcMethodAwareInterface
82
+
{
83
+
/** @var JsonRpcMethodInterface[] */
84
+
private $mappingList = [];
85
+
86
+
public function addJsonRpcMethod(string $methodName, JsonRpcMethodInterface $method): void
87
+
{
88
+
$this->mappingList[$methodName] = $method;
89
+
}
90
+
91
+
/**
92
+
* @return JsonRpcMethodInterface[]
93
+
*/
94
+
public function getMappingList() : array
95
+
{
96
+
return $this->mappingList;
97
+
}
98
+
}
99
+
```
154
100
155
-
### Service definition tag
156
-
Use `json_rpc_http_server.method_resolver` tag as following:
101
+
```yaml
102
+
mapping_aware_service:
103
+
class: App\Collector\MappingCollector
104
+
tags: ['json_rpc_http_server.method_aware']
105
+
```
106
+
107
+
### Custom method resolver
108
+
In case you want to use your method resolver implementation, use the tag `json_rpc_http_server.method_resolver`, it will be automatically injected inside JSON-RPC server:
0 commit comments