moaction / jsonrpc-server
Jsonrpc server php implementation
Installs: 185
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/moaction/jsonrpc-server
Requires
- php: >=5.3.0
- moaction/jsonrpc-common: >=1.5
- psr/log: 1.0.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2025-10-07 05:50:14 UTC
README
Server implementation for JsonRPC 2.0 protocol
http://www.jsonrpc.org/specification
Usage
Basic usage
$server = new \Moaction\Jsonrpc\Server\BasicServer(); $server->addMethod('getUser', function($id) { return array( 'id' => $id, 'name' => 'UserName' ); }); echo $server->run(file_get_contents('php://input'));
Error reporting
Every exception in method call will be converted into error object in response. You can specify code and message in exception.
$server->addMethod('errorTest', function() { throw new \Exception('Strange server error', 42); });
Server response will be:
{"jsonrpc": "2.0", "error": {"code": 42, "message": "Strange server error"}, "id": null}
If you do not provide code, default "Server Error" code -32000 will be used. As well as error message.