paulgessinger / jsonrpc
Lightweight framework for JsonRpc APIs.
Requires
- php: >=5.3.0
- monolog/monolog: *
- paulgessinger/common: *
- phpdocumentor/reflection-docblock: 1.0.*
- pimple/pimple: 2.0.*@dev
- symfony/http-foundation: 2.5.*@dev
Requires (Dev)
- mockery/mockery: dev-master@dev
- phpunit/dbunit: >=1.2
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-12-21 16:25:48 UTC
README
#JSONRPC for PHP
Allows you to write simple and fast JSON RPC APIs by exposing arbitrary objects to HTTP POST requests.
Installation
By all means; use Composer!
- Get Composer
- Add
"paulgessinger/jsonrpc": "dev-master"
to your require - Install dependencies with
composer install
Getting started
Put something like this in your bootstrap file (e.g. index.php).
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
{ "jsonrpc":"2.0", "id":1, "method":"Sample.divide", "params": [11, 5] }
(documented in the JSON RPC specification).
while Sample looks like
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
{ "jsonrpc":"2.0", "id":1, "result":2.2 }
Have fun.
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
.
Contributors
License
The MIT License (MIT)
Copyright (c) 2013 Paul Gessinger
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.