PHP code example of robertasproniu / php-json-rpc

1. Go to this page and download the library: Download robertasproniu/php-json-rpc 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/ */

    

robertasproniu / php-json-rpc example snippets




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 
json
""robertasproniu/php-json-rpc": "~1.0"
}