unlimix / yii2-json-rpc
description
v1.1.4
2014-11-14 13:11 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: dev-master
README
JsonRpc Server and Client for Yii2
##Usage Server
- Install with Composer
"require": { "unlimix/yii2-json-rpc": "dev-master", }, php composer.phar update
- Add action to controller
public function actions() { return array( 'index' => array( 'class' => '\unlimix\jsonRpc\Action', ), ); } public function sum($a, $b) { return $a + $b; }
- TEST:
function sendRPC(){ $.ajax({ url: 'YOUR URL', data: JSON.stringify({ "jsonrpc": "2.0", "id": '<?php echo md5(microtime()); ?>', "method": "sum", "params": [1, 2] }), type: 'POST', dataType: 'JSON', contentType: 'application/json-rpc', complete: function (xhr, status) { console.log(xhr); console.log(status); } }); }
- Enjoy!