datto / json-rpc-simple
Request-to-class mapping extension for JSON-RPC library
Installs: 16 008
Dependents: 3
Suggesters: 0
Security: 0
Stars: 4
Watchers: 6
Forks: 4
Open Issues: 0
Requires
- datto/json-rpc: ~3.0
- monolog/monolog: ~1.0
This package is not auto-updated.
Last update: 2024-11-09 19:19:34 UTC
README
This is a request-to-class mapping extension for the php-json-rpc library. Its purpose is to eliminate the need to write manual mapping functions for API endpoints by providing an automatic mapping of the JSON-RPC method
and params
arguments to a matching PHP class, method and parameters.
Examples
First write an API end point:
<?php namespace Datto\API; class Math { public function subtract($a, $b) { return $a - $b; } }
Then use the API (with the default namespace Datto\API
):
// This will instantiate an object of the type `Datto\API\Math`, // call the `subtract` method, and return a corresponding JSON-RPC response. $server = new Server(new Simple\Evaluator()); echo $server->reply('{"jsonrpc": "2.0", "method": "math/subtract", "params": {"a": 3, "b": 2}, "id": 1}');
Or to use a custom root namespace (here: Datto\NodeAPI
):
$server = new Server(new Simple\Evaluator(new Simple\Mapper('Datto\\NodeAPI'))); echo $server->reply('...');
Requirements
- PHP >= 5.3
Installation
"require": { "datto/json-rpc-simple": "~4.0" }
License
This package is released under an open-source license: LGPL-3.0.
Author
Written by Philipp C. Heckel.