Download the PHP package yoanm/jsonrpc-server-sdk without Composer
On this page you can find all versions of the php package yoanm/jsonrpc-server-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yoanm/jsonrpc-server-sdk
More information about yoanm/jsonrpc-server-sdk
Files in yoanm/jsonrpc-server-sdk
Package jsonrpc-server-sdk
Short Description Server SDK to convert a json-rpc request string into json-rpc response string
License MIT
Informations about the package jsonrpc-server-sdk
PHP JSON-RPC server sdk
Simple server SDK to convert a json-rpc request string into json-rpc response string.
See yoanm/symfony-jsonrpc-http-server for automatic dependency injection.
See yoanm/jsonrpc-params-symfony-validator-sdk for params validation.
See yoanm/jsonrpc-server-doc-sdk for documentation generation.
How to use
Sdk requires only two things :
- A method resolver : must implements JsonRpcMethodResolverInterface, resolving logic's is your own.
- Methods : JsonRpc methods which implements JsonRpcMethodInterface
Sdk optionally provide :
- Events dispatch
- Params validation
Simple Example
JSON-RPC Method
Array method resolver (simple example)
You can use Psr11 method resolver as example
Then add your method to the resolver and create the endpoint :
Once endpoint is ready, you can send it request string :
$responseString
will be the following string depending of method returned value :
Events dispatch example
Simple event dispatcher
You can use the one used for behat tests as example
Then bind your listeners to your dispatcher:
And bind dispatcher like following :
Events dispatched
Basic request lifecycle
-
json_rpc_server_skd.on_request_received
/Acknowledge\OnRequestReceivedEvent
Dispatched when a request has been passed to the endpoint and successfully deserialized.
N.B. : Lonely cases where this event is not dispatched are when the request string is not a valid JSON-RPC request.
It include :
- Parse error exception (malformed json string)
-
For simple request only, in case of Invalid request (not an object / missing required properties / ...).
:warning: For batch request containing Invalid SubRequest, this event will still be dispatched
-
Either
-
json_rpc_server_skd.on_method_success
/Action\OnMethodSuccessEvent
Dispatched only in case JSON-RPC method has been successfully executed.
-
json_rpc_server_skd.on_method_failure
/Action\OnMethodFailureEvent
Dispatched only in case JSON-RPC method throw an exception during execution.
-
-
json_rpc_server_skd.on_response_sending
/Acknowledge\OnResponseSendingEvent
Dispatched when a response has been successfully serialized by the endpoint and will be returned.
Additional events
Batch request
-
json_rpc_server_skd.on_batch_sub_request_processing
/Acknowledge\OnBatchSubRequestProcessingEvent
Dispatched before that a sub request will be processed.
-
json_rpc_server_skd.on_batch_sub_request_processed
/Acknowledge\OnBatchSubRequestProcessedEvent
Dispatched after that a sub request has been processed (regardless of the success or failure of the sub request method execution).
Exception
json_rpc_server_skd.on_exception
/ Action\OnExceptionEvent
Dispatched when an exception occurred during sdk execution
Action vs Acknowledge events
Acknowledge
They have only an acknowledge purpose.
They are grouped under Yoanm\JsonRpcServer\Domain\Event\Acknowledge
namespace.
Action
They allow you to override stuffs.
They are grouped under Yoanm\JsonRpcServer\Domain\Event\Action
namespace.
Here, the list :
Action\OnMethodSuccessEvent
allow you to update/change the result of the method.Action\OnMethodFailureEvent
allow you to update/change the exception thrown by the method.Action\OnExceptionEvent
allow you to update/change the exception thrown.
Params validation example
You can use this JSON-RPC params symfony validator as example
To validate params for a given method, do the following :
Contributing
See contributing note
All versions of jsonrpc-server-sdk with dependencies
ext-json Version *