bednic / json-rpc
JSON RPC 2.0 implementation
3.3.0
2023-04-20 15:55 UTC
Requires
- php: ^8.0
- ext-json: *
Requires (Dev)
- doctrine/instantiator: 1.5.*
- opis/json-schema: ^1.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.0
README
JSON RPC Docs
Usage
- Create controller implementing ProcedureController
- Pass the controller to dispatcher
- Handle json request data with
Dispatcher::dispatch(string $data)
- 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.