simpod / json-rpc
PHP JSON-RPC 2.0 PSR-7 Message factory
Fund package maintenance!
Requires
- php: ^8.4
- ext-json: *
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- cdn77/coding-standard: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^2.0.0
- phpstan/phpstan-phpunit: ^2.0.0
- phpstan/phpstan-strict-rules: ^2.0.0
- phpunit/phpunit: ^13.0
- psr-mock/http: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-14 11:59:12 UTC
README
Installation
Add as Composer dependency:
composer require simpod/json-rpc
Response extraction
Construct SimPod\JsonRpc\Extractor\ResponseExtractor with a PSR-7 message to read
its JSON-RPC response fields. The constructor validates the fields used by the
typed getters before they can be read:
- The response must be a JSON object with a string
jsonrpcfield. - An optional
idmust be a string, integer ornull. - A non-null
errormust be an object with an integercodeand a stringmessage.
Malformed fields cause SimPod\JsonRpc\Extractor\MalformedResponse, which extends
UnexpectedValueException. Invalid JSON still causes JsonException. Both
exceptions are thrown by the constructor, not by a getter.
This is field validation, not full JSON-RPC protocol validation. No method is
required. Unknown fields are accepted, and result and error.data remain
unrestricted JSON values, decoded as associative arrays where applicable. A
response can contain both an error and a partial result. Application-specific
validation, such as checking result shapes or matching an expected request ID,
remains the caller's responsibility.