سؤال

I have JSON-RPC2 server which provides interface to some services

$server = new Server;
$server->service1 = new Service1($this);
$server->service2 = new Service2($this);

I am wondering, if there is any (preferably PHP) client, which is able to call the methods of these services, as I need it for debug purposes.

I tested one client, which is able to call methods directly:

$client = new jsonRPCClient('http://localhost/jsonrpcphp/server.php');

// This works
$response = $client->giveMeSomeData('name');

// This doesn't
$response = $client->service1->giveMeSomeData('name');

My original client is CoffeScript application, which calls the methods in this way:

@get("api").call "service1.giveMeSomeData", "name", (result) =>

Is there any JSON-RPC2 client for PHP which I could use in the same way?

هل كانت مفيدة؟

المحلول

JSON-RPC is a very simple protocol. The namespace of an endpoint is FLAT. There aren't classes exposed (let alone multiple classes) from a single endpoint.

When the CoffeeScript client is calling service1.giveMeSomeData, it's literally asking the PHP web-service to execute an endpoint method with the name service1.giveMeSomeData. If your web-service then routes that to the giveMeSomeData method in an instance of some class currently assigned to the instance Service1, well that's up to it! (the PHP service side). This is NOT a feature of JSON-RPC, it's something made up by the end-point router you're using.

The equivalent call on the PHP client side might be something like $client->call('Service1.giveMeSomeData', array('name')) It depends on the JSON-RPC library you use. Some PHP client libraries construct an instance of an ad-hoc class, which implements the PHP __call method, such that any un-recognised method names are re-directed as calls to the generic RPC call method in that class.

To be clear, there are not multiple namespaces being served from the JSON-RPC endpoint, just a single flat namespace which can include methods with . (dot) characters in their names. How your web-service endpoint routes those calls to PHP functions/methods is completely up to you/it.

PS. You'll get much better help if you explain what client & server libraries you're using in PHP for JSON-RPC (there are many, of varying quality and completeness).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top