PHP code example of jeyroik / extas-http-jsonrpc

1. Go to this page and download the library: Download jeyroik/extas-http-jsonrpc 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/ */

    

jeyroik / extas-http-jsonrpc example snippets


use extas\interfaces\http\IHasJsonRpcRequest;
use extas\components\Item;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use extas\interfaces\http\IHasJsonRpcResponse;
use extas\components\http\THasJsonRpcRequest;
use extas\components\http\THasJsonRpcResponse;

/**
 * @var RequestInterface $request
 * @var ResponseInterface $response
 */

$item = new class ([
    IHasJsonRpcRequest::FIELD__PSR_REQUEST => $request,
    IHasJsonRpcResponse::FIELD__PSR_RESPONSE => $response
]) extends Item {
    use THasJsonRpcResponse;
    use THasJsonRpcRequest;
    
    protected function getSubjectForExtension() : string{
        return 'test';
    }
};

print_r(
    $item->successResponse(
        $item->getJsonRpcRequest()->getId(),
        [
            //some data
        ]
    )
);