PHP code example of pradosoft / prado-rpc

1. Go to this page and download the library: Download pradosoft/prado-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/ */

    

pradosoft / prado-rpc example snippets


namespace Application\Api;

use Prado\Web\Services\TRpcApiProvider;

class CustomersApi extends TRpcApiProvider
{
	public function registerMethods(): array
	{
		return [
			'getCustomer'   => ['method' => [$this, 'getCustomer']],
			'listCustomers' => ['method' => [$this, 'listCustomers']],
		];
	}

	public function getCustomer(int $id): array { /* ... */ }
	public function listCustomers(string $status = 'active'): array { /* ... */ }
}

use Prado\IO\Rpc\TRpcClient;

$client = TRpcClient::create('json', 'https://host/rpc');

$customer = $client->getCustomer(42);
$orders   = $client->listOrders($customer['id']);

$client = TRpcClient::create('xml', 'https://host/rpc');        // XML-RPC
$notify = TRpcClient::create('json', 'https://host/rpc', true); // notification mode