Quick Start
1) Create an entry point
Create public/index.php:
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Lumen\JsonRpc\Config\Config;
use Lumen\JsonRpc\Server\JsonRpcServer;
$config = new Config([
'handlers' => [
'paths' => [__DIR__ . '/../handlers'],
'namespace' => 'App\Handlers\',
],
]);
$server = new JsonRpcServer($config);
$server->run();
2) Create a handler
Create handlers/User.php:
<?php
declare(strict_types=1);
namespace App\Handlers;
use Lumen\JsonRpc\Support\RequestContext;
final class User
{
public function get(RequestContext $context, int $id): array
{
return [
'id' => $id,
'name' => 'Example User',
];
}
}
3) Send a request
curl -X POST http://localhost:8000/ \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"user.get","params":{"id":1},"id":1}'
4) Response
{"jsonrpc":"2.0","result":{"id":1,"name":"Example User"},"id":1}
The mental model
| JSON-RPC Method | Handler Class | Method |
|---|---|---|
user.get | handlers/User.php | get() |
user.create | handlers/User.php | create() |
system.health | handlers/System.php | health() |
No manual method registry. No hidden auto-generated procedures. Just handler.method.