Skip to content

About

PHP factory for creating JSON RPC 2.0 PSR-7 requests

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Repository files navigation

JSON RPC 2.0 PSR-7 Message Factory

GitHub Actions Code Coverage Downloads Packagist

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 jsonrpc field.
  • An optional id must be a string, integer or null.
  • A non-null error must be an object with an integer code and a string message.

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.

About

PHP factory for creating JSON RPC 2.0 PSR-7 requests

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages