2017 © Pedro Peláez
 

library jsonrpc

Lightweight framework for JsonRpc APIs.

image

paulgessinger/jsonrpc

Lightweight framework for JsonRpc APIs.

  • Friday, July 15, 2016
  • by paulgessinger
  • Repository
  • 1 Watchers
  • 0 Stars
  • 162 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

JSONRPC for PHP

Build Status, (*1)

Allows you to write simple and fast JSON RPC APIs by exposing arbitrary objects to HTTP POST requests., (*2)

Installation

By all means; use Composer!, (*3)

  1. Get Composer
  2. Add "paulgessinger/jsonrpc": "dev-master" to your require
  3. Install dependencies with composer install

Getting started

Put something like this in your bootstrap file (e.g. index.php)., (*4)

use PG\JsonRpc\Server ;

include __DIR__.'/vendor/autoload.php' ;

$server = new Server() ;

$server->expose('Sample', 'PG\JsonRpc\tests\sample\Sample') ;

$server->run() ;

You can then do POST requests on it with a JSON body in the form of, (*5)

{
    "jsonrpc":"2.0",
    "id":1,
    "method":"Sample.divide",
    "params": [11, 5]
}

(documented in the JSON RPC specification)., (*6)

while Sample looks like, (*7)

namespace PG\JsonRpc\tests\sample;
use PG\JsonRpc\Exception\ArgumentException;

class Sample {
    public function divide($a, $b) {
        return $a/$b ;
    }

    // ...
}

You will get a reponsse in the form of, (*8)

{
    "jsonrpc":"2.0",
    "id":1,
    "result":2.2
}

Have fun., (*9)

Tests

The lib tries to be fully unit tested. Go take it for a spin, go to the lib's root directory and run phpunit. PHPUnit is also included in the require-devs so you can get it with composer install --dev or composer update., (*10)

Contributors

License

The MIT License (MIT), (*11)

Copyright (c) 2013 Paul Gessinger, (*12)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*13)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*14)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*15)

The Versions