Tivoka

JSON-RPC done right!

View project onGitHub

Do JSON-RPC. With Tivoka. It's as easy as that!
For convenience, you can easily switch between JSON-RPC 1.0 and JSON-RPC 2.0 without having to change your code.

Tivoka provides client and server for PHP 5.3+ -- learn more about JSON-RPC at http://jsonrpc.org/.

Examples

These are just some quick examples. For more details see the wiki.

Do a request

<?php
$connection = Tivoka\Client::connect('http://exapmle.com/api')
$request = $connection->sendRequest('substract', array(51, 9));
print $request->result;// 42
?>

Create a server

<?php
$methods = array(
    'substract' => function($params) {
        list($num1, $num2) = $params
        return $num1 - $num2;
    }
);
Tivoka\Server::provide($methods)->dispatch();
?>

Links

Installation

Install composer package

  1. Set up composer.json:
{
  require:{"tivoka/tivoka":"*"}
}
  1. Run composer:
$ php composer.phar install

Now, include 'vendor/autoload.php'

Install through pear

  1. Run the following:
$ pear channel-discover pearhub.org
$ pear install pearhub/tivoka

Now, include 'tivoka/include.php'

Download

  1. Grab the source using git clone https://github.com/marcelklehr/tivoka.git.
    Or download it.

Now, include 'path/to/tivoka/include.php'

License

Copyright 2011-2012 by Marcel Klehr
MIT License.