PHP code example of kelemen / json-rpc-20-processor
1. Go to this page and download the library: Download kelemen/json-rpc-20-processor library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kelemen / json-rpc-20-processor example snippets
use MyHandlers\AddHandler;
use Kelemen\JsonRpc20\Processor;
use Kelemen\JsonRpc20\Processor\Transform\FractalTransform;
$raw = file_get_contents('php://input');
$handler = new AddHandler();
$processor = new Processor();
// Add new handler for method "add"
$processor->registerHandler('add', [$handler, 'add']);
// Response is Response object or array of Response object for batch request
$response = $processor->process($raw);
// Transform result to array or json
$fractalTransform = new FractalTransform();
return $fractalTransform->toArray($response);