mtoolkit / mtoolkit-network
The network module of MToolkit framework
0.0.3
2016-08-06 12:02 UTC
Requires
- php: >=5.3.0
- mtoolkit/mtoolkit-controller: 0.0.2
- mtoolkit/mtoolkit-core: dev-master
- mtoolkit/mtoolkit-model: dev-master
Requires (Dev)
- phpunit/phpunit: 5.1.*
This package is not auto-updated.
Last update: 2024-12-21 20:01:49 UTC
README
The network module of MToolkit framework.
RPC-JSON
JSON-RPC is a remote procedure call protocol encoded in JSON
Server
Create a RPC-JSON server is simple. This example implements an web service to sum 2 number:
class RPCJsonWebService extends MRPCJsonWebService { public function __construct(){} public function sum($data) { $response = new MRPCJsonResponse(); $response->setId( $this->getRequest()->getId() ); $response->setResult( array( 'sum' => $data['a'] + $data['b'] ) ); $this->setResponse( $response ); } }
Client
This is the client of the above example:
$request = new MRPCJsonRequest(); $request->setId(1) ->setMethod('sum') ->setParams( array('a'=>1, 'b'=>2) ); $client = new MRPCJsonClient($url); $client->call($request); $response = $client->getResponse();