huangdijia/laravel-jsonrpc

jsonrpc for laravel

2.0.0 2021-09-28 15:11 UTC

README

Latest Version on Packagist Total Downloads GitHub license

Installation

composer require huangdijia/laravel-jsonrpc

Usage

As Server

Controller

use Huangdijia\JsonRpc\Traits\JsonRpcServer;

class ExampleController extends Controller
{
    use JsonRpcServer;

    public function action()
    {
        return 'hello, json-rpc';
    }
}

Route

Route::middleware([Huangdijia\JsonRpc\Middleware\JsonRpcMiddleware::class])->group(function() {
    Route::post('/example', ExampleController::class);
});

As Client

$client = new Huangdijia\JsonRpc\Client($url);
$result = $client->action(); // hello, json-rpc