unlimix/yii2-json-rpc

description

v1.1.4 2014-11-14 13:11 UTC

This package is not auto-updated.

Last update: 2025-07-05 20:31:36 UTC


README

JsonRpc Server and Client for Yii2

##Usage Server

  1. Install with Composer
"require": {
    "unlimix/yii2-json-rpc": "dev-master",
},

php composer.phar update
  1. Add action to controller
public function actions()
{
    return array(
        'index' => array(
            'class' => '\unlimix\jsonRpc\Action',
        ),
    );
}

public function sum($a, $b) {
	return $a + $b;
}
  1. 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);
			}
		});
	}
  1. Enjoy!