maoxuner/laravel-jsonrpc
最新稳定版本:v1.3.1
Composer 安装命令:
composer require maoxuner/laravel-jsonrpc
包简介
JSON-RPC 2.0 Server/Client For Laravel
README 文档
README
Entrypoint
Add route for jsonrpc entrypoint
\Illuminate\Support\Facades\Route::post('/jsonrpc', 'maoxuner\LaravelJsonRpc\Server\Server@entrypoint');
Configure
php artisan vendor:publish --tags=jsonrpc
Do some modification such as changing namespace to App\\Actions
Create a procedure
Create a procedure class under the namespace configured before with a public function handle.
<?php
namespace App\Actions;
class Ping
{
public function handle(): string
{
return 'Pong';
}
}
<?php
namespace App\Actions;
class Say
{
public function handle(string $name, string $foo = 'foo', ?string $bar = null): array
{
return [
'message' => 'Hello, '.$name.'!',
'foo' => $foo,
'bar' => $bar,
];
}
}
Test Client
Use tinker create a client and then call Ping procedure. Params are supported by passing param position/name indexed array as second argument to execute.
php artisan tinker
$client = new \maoxuner\LaravelJsonRpc\Client\Client(\Illuminate\Support\Facades\Http::baseUrl('http://foo-bar/jsonrpc'));
echo $client->execute('Ping');
dump($client->execute('Say', ['World', 'oof']));
dump($client->execute('Say', ['bar' => 'rab', 'name' => 'World']));
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-22