LightRPC: JSON-RPC 2 Client for PHP

Words
89
Reading
1 min
Listen
Play
8y

New Project: LightRPC for PHP

A simple, yet powerful JSON-RPC 2 client for PHP. Inspired by Busy's Javascript LightRPC.

This project allows easily callying and interacting with a JSON-RPC server using PHP.

  • Examples:

// alias.
use LightRPC\Client;

// start a client instance.
$client = new Client('https://api.steemit.com');

// call it.
$response = $client->call('follow_api', 'get_follow_count', ['hernandev']);

/*
  * Alternative method: using Request classes:
  */
// create a request instance.
$request = new Request('follow_api', 'get_follow_count', ['hernandev']);

// send it.
$response = $client->send($request);
  • Easy response parsing:
// wanna check for errors?
$response->isError();


// use the magic result getters.
$response->account;           // 'hernandev'
$response->follower_count;    // 123
$response->following_count;   // 123

// OR

// use a get method:
$response->get('account');           // 'hernandev'
$response->get('follower_count');    // 123
$response->get('following_count');   // 123

// OR

// get all result OR error data:
$response->data();  // [ 'account' => 'hernandev', 'following_count' => 123, 'follower_count' => 123]
$response->get();   // [ 'account' => 'hernandev', 'following_count' => 123, 'follower_count' => 123]

// OR

// If you are a boring person, just get the full response as array.
$response->toArray(); // [ 'jsonrpc' => '2.0', 'id' => 0, 'result' => ['foo' => 'bar']]

// You are really boring you know, wanna as JSON string?
(string) $response; // '{"jsonrpc":"2.0","id":0,"result":{...}}

  • Technology Stack:

PHP 7.1+ with 100% unit test coverage. This project is simple, yet powerful.

  • Roadmap:

This project is going to be the base RPC client for a new Steem PHP library.

  • How to contribute?

Contact me on Discord at hernandev#5834 or though Github issues.



Posted on Utopian.io - Rewarding Open Source Contributors