bednic/json-rpc

JSON RPC 2.0 implementation

3.3.0 2023-04-20 15:55 UTC

This package is auto-updated.

Last update: 2024-12-03 20:15:50 UTC


README

JSON RPC Docs

JSON-RPC

Usage

  1. Create controller implementing ProcedureController
  2. Pass the controller to dispatcher
  3. Handle json request data with Dispatcher::dispatch(string $data)
  4. Fetch results by calling Dispatcher::result()

class MyController implements \JSONRPC\ProcedureController {

    public function subtract(int $a, int $b){
        return $a - $b;
    }
}

$app->post('/rpc', function($request){
    $dispatcher = new \JSONRPC\Dispatcher(new \App\Controller\MyController());
    $request->getBody();
    $response = $dispatcher->dispatch(json_encode($req));
    $result = $response->getResult();
    return json_encode($result);
});

Example

See tests in this repo.