Zend_Json_Server and JSON-RPC 2.0

Zend_Json_Server and JSON-RPC 2.0
The 4 available parameters are:
+ jsonrpc – the version you are using; I’m using 2.0.

+ method – the name of the method you want to call in the server.
+ params – object of parameters your method needs. If you don’t need any, don’t send this param.
+ id – an identifier (anything you want) that will be sent to and from the server for this request.

I’m using Zend_Http_Client() to make the request and here is an example:


And here is what I see in my browser when I make the call:




Basically, all I had to do was
+ create an array of all the parameters I want to send on my request object. I’m calling the find method and passing an id
+ create a new client object
+ set the url to where your setting up your Zend_Json_Server
+ set the client to post (Zend_Json_Server only seems to handle post at this time)
+ json_encode your parameters array
+ pass the json_encoded object to the setRawData so it passes exactly what we want which is one json object to the server
+ call request to send the request and finally get body to show the response.

Here is my code for the server.php file so you can see how I’m setting up the server:


Zend_Json_Server and JSON-RPC 2.0

No comments:

Post a Comment