2017 © Pedro Peláez
 

library json-rpc

JSON-RPC 2.0 server for PHP

image

acelot/json-rpc

JSON-RPC 2.0 server for PHP

  • Monday, July 7, 2014
  • by acelot
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

JSON-RPC

JSON-RPC 2.0 Server for PHP 5.3, (*1)

Features

  • Supports batch requests
  • Full service independence from the server
  • Errors transmitted by throwing standard PHP exceptions (InvalidArgumentException, Exception)
  • PSR-4 compliant code structure
  • A small amount of code
  • Available via composer

Usage

Initialize server. For example you can do this in some route callback or controller action. By default, the server uses a PhpInput transport, which receives data from php://input. You can pass custom transport realization via second argument to the server constructor., (*2)

$server = new \Acelot\JsonRpc\Server(new \MyNamespace\MyApi());
$server->dispatch();

Write your API, (*3)

namespace MyNamespace;

class MyApi
{
    public function getPost($id)
    {
        if (empty($id)) {
            throw new \InvalidArgumentException('Specify post id');
        }

        /*
         * Post retrieving code here
         */

        return $post;
    }

    public function createPost($title, $body)
    {
        /*
         * Post creating code here. Any exception will be caught and sent to the client in the right form.
         */

        return true;
    }
}

Now you can call remote procedures via json:, (*4)

{jsonrpc: "2.0", method: "getPost", params: [1], id: null}, (*5)

or, (*6)

{jsonrpc: "2.0", method: "createPost", params: ["New post", "Hello, world!"], id: null}, (*7)

Requirements

PHP 5.3 or higher, (*8)

License

This project is released under the MIT public license., (*9)

The Versions

07/07 2014

dev-master

9999999-dev https://github.com/acelot/json-rpc

JSON-RPC 2.0 server for PHP

  Sources   Download

MIT

server json-rpc

07/07 2014

0.1.0

0.1.0.0 https://github.com/acelot/json-rpc

JSON-RPC 2.0 server for PHP

  Sources   Download

MIT

server json-rpc