PHP code example of tochka-developers / jsonrpc-client
1. Go to this page and download the library: Download tochka-developers/jsonrpc-client 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' );
tochka-developers / jsonrpc-client example snippets
$app->configure('jsonrpc-client' );
$app->withFacades();
$app->register(Tochka\JsonRpcClient\JsonRpcClientServiceProvider::class);
$result = Api::fooBar('Some text' );
$api = Api::batch();
$api->foo('params' );
$api->bar(123 );
$api->someMethod(1 , true );
[$resultFoo, $resultBar, $resultSome] = $api->execute();
$result = Api::cache(10 )->fooBar('Some text' );
$api = Api::batch();
$resultFoo = $api->cache(10 )->foo('params' );
$resultBar = $api->bar(123 );
$resultSome = $api->cache(60 )->someMethod(1 , true );
[$resultFoo, $resultBar, $resultSome] = $api->execute();
class SomeMiddleware
{
public function handle (\Tochka\JsonRpcClient\Request $request, \Closure $next) : void
{
return $next($request);
}
}
class SomeMiddleware implements \Tochka \JsonRpcClient \Contracts \OnceExecutedMiddleware
{
public function handle (array $requests, \Closure $next) : void
{
return $next($requests);
}
}
'middleware' => [
\Tochka\JsonRpcClient\Middleware\AuthTokenMiddleware::class => [
'name' => 'X-Access-Key' ,
'value' => 'TokenValue' ,
],
]
use Tochka \JsonRpcClient \Request ;
class AuthTokenMiddleware implements \Tochka \JsonRpcClient \Contracts \OnceExecutedMiddleware
{
public function handle (array $request, \Closure $next, $value, $name = 'X-Access-Key' )
{
return $next($request);
}
}
php artisan vendor:publish --provider="Tochka\JsonRpcClient\JsonRpcClientServiceProvider"
php artisan jsonrpc:generateClient connection
php artisan jsonrpc:generateClient