Bundle for JSON-RPC 2.0. You can use as standalone library. Or with Symfony.
- Validation. Based on Symfony Validator component.
- Deserialization. Based on JMS.
- Customization. Change your rules for JSON-RPC 2.0.
- Install package:
composer require zored/speech
. - Add bundle
new Zored\SpeechBundle\ZoredSpeechBundle()
to your Symfony kernelapp/AppKernel.php
. - Add route to default endpoint:
routing.yml
:json_rpc: defaults: { _controller: ZoredSpeechBundle:Default:jsonRpc } methods: [POST] # Or GET for Zored RPC. path: /json-rpc
- Add service with your JSON-RPC methods in
services.yml
:services: your.service: # Replace with your own class: class: 'Zored\SpeechBundle\Test\JsonRpc\Greeter'
- Allow this service to run in default controller via
parameters.yml
:parameters: zored.speech.controller.context.service_ids: ['your.service']
- Clear caches.
- Test:
curl http://example.com/json-rpc/ \ --data '{"id":"1", "method":"your.service:greet", "params":{"person":{"name":"bob","age":19}},"jsonrpc":"2.0"}'
- See example in
web/index.php
- Run there server with
php -S 127.0.0.1:8080
- Test:
curl http://127.0.0.1:8080 \ --data '{"id":"1", "method":"your.service:greet", "params":{"person":{"name":"bob","age":19}},"jsonrpc":"2.0"}'
- See default controller if you need multiple JSON-RPC endpoints.
- See tests to know how it works.
- Your request JSON string goes to endpoint which handles it and returns Symfony response.
- Endpoint chooses which request passer can pass JSON string to request handler.
- Request passer also deserializes JSON to object and validates it.
- Request passer passes request object to request handler that pushes request somewhere to get response.
- Now service handler is used to:
- Deserialize request
params
if set with parameter converter. - Call public method of service with these params. Services are restricted with
ServiceContext
. For default controller seezored.speech.controller.context
parameter. - Wait for
array
orAbstractResponse
.
- Deserialize request
- Now service handler is used to:
- Request then passed back and serialized to array.
You can see available events here.