Use Composer
"require" : {
"robertasproniu/php-json-rpc": "~1.0"
}
require_once 'vendor/autoload.php';
use JsonRpc\Server;
$server = new Server();
$server
->withCallback('add', function($a, $b) {
return $a + $b;
})
// OR
->withCallback('substract', 'className', 'methodName');
$server
->withMiddleware(function($request, $response) {
// add logic here
return true; // will invalidate middleware
});
$server->execute(); // return json
// OR
$server->execute($payload); // pass json payload