datto/json-rpc
Lightweight PHP library for building and parsing JSON-RPC 2.0 messages. Fully spec compliant, 100% unit-tested, and transport-agnostic so you can use HTTP, SSH, or any channel. Includes simple Client/Server APIs and working examples.
preEncode/postDecode hooks and rawReply method allow custom serialization/deserialization (e.g., for binary payloads, protobuf, or Avro).datto/json-rpc-http for RESTful APIs (Lumen/Laravel HTTP middleware).php artisan rpc:call).User::find() exposed via JSON-RPC).rpc.method.called).json-rpc-http, Guzzle, or custom socket code), adding complexity.ApplicationException to Laravel’s HttpResponse).Response object refactor) may require migration effort.json-rpc-http is recommended.ProblemDetails or custom responses?Log facade or Prometheus).| Laravel Component | Integration Strategy |
|---|---|
| HTTP Layer | Use datto/json-rpc-http as a Lumen/Laravel middleware or route handler. |
| Queues | Dispatch RPC calls as queued jobs (e.g., JsonRpcJob extending ShouldQueue). |
| Artisan CLI | Expose RPC methods via Artisan::command() for local development tools. |
| Middleware | Create JsonRpcMiddleware to parse/validate incoming JSON-RPC requests. |
| Service Providers | Register RPC endpoints in boot() (e.g., Api::addMethod('user.create', [UserService::class, 'create'])). |
| Event System | Emit JsonRpcCalled events to trigger side effects (e.g., logging, analytics). |
| Validation | Use Laravel’s Form Request validation for RPC method parameters. |
/api/rpc).json-rpc-http and Laravel’s Route::post().dispatch(new JsonRpcJob($request))).auth:api for protected endpoints).Cache::remember()).user.get, order.process) in a schema (OpenAPI/Swagger).Api and Server classes in Laravel’s AppServiceProvider.json-rpc-http), queues, or CLI.phpunit and contract tests (e.g., Pact).try-catch for ErrorException and ApplicationException.Validator.connect_timeout in HTTP transport.datto/json-rpc to a minor version (e.g., ^6.0).-32601 for invalid method).Cache::forever() for immutable data).Client::batch() for multiple calls in one request.| Failure Scenario | Mitigation Strategy |
|---|---|
| Malformed JSON-RPC Request | Use Laravel’s Validator or JsonRpcMiddleware to reject invalid input. |
| Transport Layer Failure | Implement retries (e.g., Guzzle’s retry middleware) or circuit breakers. |
| Server Overload | Rate-limit endpoints (e.g., Laravel throttle middleware). |
| Queue Backlog | Monitor Horizon and scale workers. |
| Dependency Vulnerabilities | Pin datto/json-rpc and dependencies in composer.json. |
| Schema Drift | Use contract tests to ensure RPC methods match expectations. |
How can I help you explore Laravel packages today?