Skip to content

Implementation of JSON-RPC for PHP 5.4+. Can be used to create API service for your project. Specification: http://www.jsonrpc.org/specification

License

Notifications You must be signed in to change notification settings

egorgrushko/SimpleJSONRPC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SimpleJSONRPC

Implementation of JSON-RPC for PHP 5.4+. Can be used to create API service for your project. Specification: http://www.jsonrpc.org/specification

Install

Via Composer

$ composer require egorgrushko/simplejsonrpc

Usage

Example implementation of http://www.jsonrpc.org/specification#examples

class Foo
{
    public $data;

    public function __construct($data)
    {
        $this->data = $data;
    }

    public function __destruct()
    {
        
    }

    public function sum($param1, $param2, $param3)
    {
        return $param1 + $param2 + $param3;
    }

    public function subtract($minuend, $subtrahend)
    {
        return $minuend - $subtrahend;
    }

    public function notify_hello()
    {
        return 2 + 2;
    }

    public function get_data()
    {
        return $this->data;
    }
}
$request = isset($_REQUEST['request']) ? $_REQUEST['request'] : null; // Read JSON string

$fooObject = new Foo(array("hello", 0)); // Create the class object with the required methods and properties

$server = new SimpleJSONRPCServer($fooObject); // Create server object

$fooObject->data[1] = 5; // You can change properties before or between processing RPC

echo $server->process($request); // Execute the JSONRPC string processing. Returns result of processing

License

The MIT License (MIT). Please see License File (LICENSE.md) for more information.

About

Implementation of JSON-RPC for PHP 5.4+. Can be used to create API service for your project. Specification: http://www.jsonrpc.org/specification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages