Add as Composer dependency:
composer require simpod/json-rpcConstruct 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.