PHPackages                             zjkiza/http-response-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. zjkiza/http-response-validator

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

zjkiza/http-response-validator
==============================

A Symfony bundle for HTTP responses validating using a simple Result monad and handler chains.

v0.11.0(1mo ago)0561MITPHPPHP &gt;=8.2

Since Dec 1Pushed 1mo agoCompare

[ Source](https://github.com/zjkiza/http-response-validator)[ Packagist](https://packagist.org/packages/zjkiza/http-response-validator)[ RSS](/packages/zjkiza-http-response-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (32)Versions (12)Used By (0)

Http Response Validator Bundle
==============================

[](#http-response-validator-bundle)

A Symfony bundle for HTTP responses validating using a simple Result monad and handler chains.

The main idea: the input is `ResponseInterface` (eg from `symfony/http-client`), then through a series of handlers (pipelines) the status code is validated, the content is logged, JSON is extracted and the structure is checked. Each handler returns a `Result', so the chain breaks on the first error and throws an exception with a unique message ID.

For unit testing, you can use the `PhpUnitTool` to easily test handlers in isolation with custom inputs and expected outputs.

Characteristics
---------------

[](#characteristics)

- Declarative stacking steps over `Result::success(...)->bind(...)`
- Built-in ready-to-use handlers:
    - `ZJKiza\HttpResponseValidator\Handler\HttpResponseLoggerHandler` – validates the expected status, logs the response, and masks sensitive keys
    - `ZJKiza\HttpResponseValidator\Handler\ExtractResponseJsonHandler` – decodes the JSON body (associatively or as an object)
    - `ZJKiza\HttpResponseValidator\Handler\ArrayStructureValidateExactHandler` – validates the structure of the response using strict/exact key and type checking
    - `ZJKiza\HttpResponseValidator\Handler\ArrayStructureValidateInternalHandler` – validates the structure using internal/relaxed rules for key existence and potential type checking
- Simple extension: add your own handler and register it with a single service tag
- Clear error messages with `Message ID=` for easy tracking in logs
- `ZJKiza\HttpResponseValidator\PhpUnit\ArrayMatchesTrait` enables simple and flexible testing of array structure and values (ex. API response) in PHPUnit tests.
    - `assertArrayStructureAndValues(array $expected, array $actual)` – asserts that the actual array has the same structure and values as the expected array, allowing for flexible matching (e.g., ignoring extra keys in the actual array).
    - `assertArrayStrictStructureAndValues(array $expected, array $actual)` – asserts that the actual array has the exact same structure and values as the expected array, including the same keys and values, without allowing for any extra keys in the actual array. Supports:
    - structure check,
    - value check,
    - strict and non-strict mode,
    - custom validators (callable)

Installation
------------

[](#installation)

Add "zjkiza/http-response-validator" to your composer.json file.

```
composer require zjkiza/http-response-validator

```

Symfony integration
-------------------

[](#symfony-integration)

Bundle wires up all classes together and provides method to easily setup.

1. Register bundle within your configuration (i.e: `bundles.php`).

```
