PHPackages                             lmc/cqrs-http - 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. lmc/cqrs-http

ActiveLibrary

lmc/cqrs-http
=============

A library containing base implementations to help with Http Queries and Commands

3.1.0(2y ago)133.6k↓36.2%12MITPHPPHP ^8.2

Since May 13Pushed 2y ago11 watchersCompare

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

READMEChangelog (3)Dependencies (14)Versions (6)Used By (2)

LMC CQRS Http extension
=======================

[](#lmc-cqrs-http-extension)

[![cqrs-types](https://camo.githubusercontent.com/d2e4a1ae4631bc4819c80a7abc5aa314a298c371e9ab906ccf0eecdd16e00aaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f637172732d74797065732d707572706c652e737667)](https://github.com/lmc-eu/cqrs-types)[![Latest Stable Version](https://camo.githubusercontent.com/bd8c2892f22e97b059166fc4f711df670e68cc8fd8ae38c8c04aa5db949ccd38/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6d632f637172732d687474702e737667)](https://packagist.org/packages/lmc/cqrs-http)[![Tests and linting](https://github.com/lmc-eu/cqrs-http/actions/workflows/tests.yaml/badge.svg)](https://github.com/lmc-eu/cqrs-http/actions/workflows/tests.yaml)[![Coverage Status](https://camo.githubusercontent.com/761a6d6a7dca9c17a087ba4c6df27bf214816e1161b99f0fec91eadfe3c9b4d0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c6d632d65752f637172732d687474702f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/lmc-eu/cqrs-http?branch=main)

> A library containing base implementations to help with Http Queries and Commands. This library is an extension for [CQRS/Bundle](https://github.com/lmc-eu/cqrs-bundle) and adds support for [PSR-7](https://www.php-fig.org/psr/psr-7/).

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- Queries
    - [Query](#query)
        - [Abstract HTTP Query](#abstracthttpquery)
        - [Abstract HTTP GET Query](#abstracthttpgetquery)
    - [Query Handlers](#query-handlers)
- Commands
    - [Command](#command)
        - [Abstract HTTP Command](#abstracthttpcommand)
        - [Abstract HTTP DELETE Command](#abstracthttpdeletecommand)
        - [Abstract HTTP PATCH Command](#abstracthttppatchcommand)
        - [Abstract HTTP POST Command](#abstracthttppostcommand)
        - [Abstract HTTP PUT Command](#abstracthttpputcommand)
    - [Send Command Handlers](#send-command-handlers)
- [Response Decoders](#response-decoders)
- [Profiler Formatters](#profiler-formatters)

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

[](#installation)

```
composer require lmc/cqrs-http
```

**NOTE**: You will also need an implementation for [PSR-7](https://packagist.org/providers/psr/http-message-implementation), [PSR-17](https://packagist.org/providers/psr/http-factory-implementation) and [PSR-18](https://packagist.org/providers/psr/http-client-implementation) for HTTP extensions to work.

Query
-----

[](#query)

Query is a request which fetch a data without changing anything. [See more here](https://github.com/lmc-eu/cqrs-types#query-interface)

### AbstractHttpQuery

[](#abstracthttpquery)

A base HTTP Query, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a query*).

It also implements a `ProfileableInterface` feature.

MethodTypeDescription`getRequestType`**final**It declares a request type of a Http query to be a `Psr\Http\Message\RequestInterface``getHttpMethod`abstractIt requires a query to return a http method of a query. (see [PSR Http Message Util](https://github.com/php-fig/http-message-util))`getUri`abstractThis method returns a URI of the Query - it may be just a string or a `Psr\Http\Message\UriInterface` (PSR-7) instance.`modifyRequest`*base*If you overwrite this method, you can manipulate a `RequestInterface` instance.`getProfilerId`*base*It's a predefined creating of profiler id for a http query. It creates a profiler id based on `http method` and `uri`.`getProfilerData`*base*If you overwrite this method, you can specify additional profiler data. Default is `null` (*no data*).`__toString`*base*It's a predefined casting a Query into string, it returns a string representation of `uri`.### AbstractHttpGetQuery

[](#abstracthttpgetquery)

A base HTTP **GET** Query, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a query*).

It extends a base `AbstractHttpQuery` and predefine some abstract methods. It also adds `CacheableInterface` feature, since a GET request is mostly cacheable

MethodTypeDescription`getHttpMethod`**final**It declares a http method of this query to be `GET`.`getUri`abstractThis method returns a URI of the Query - it may be just a `string` or a `Psr\Http\Message\UriInterface` (PSR-7) instance.`getCacheTime`*base*It returns a default value for a cache time of 30 minutes.`getCacheKey`*base*It creates a `CacheKey` out of a static class name (*your implementation class name*) and a `uri`, which should create a unique enough cache key for most queries.**TIP**: If you want to use this implementation but don't need a cache, you can simply return a `CacheTime::noCache()` in your implementation of `getCacheTime` method.

Query Handlers
--------------

[](#query-handlers)

It is responsible for handling a specific Query request and passing a result into `OnSuccess` callback. [See more here](https://github.com/lmc-eu/cqrs-types#query-handler-interface).

### Http Query Handler

[](#http-query-handler)

This handler supports `Psr\Http\Message\RequestInterface` and handles it into `Psr\Http\Message\ResponseInterface`.

It also checks a status code of a response and marks it as error if it is an error code:

- 400 -&gt; `HttpBadRequestException`
- 500 -&gt; `HttpServerErrorException`

---

Command
-------

[](#command)

Command is a request which change a data and may return result data. [See more here](https://github.com/lmc-eu/cqrs-types#command-interface)

### AbstractHttpCommand

[](#abstracthttpcommand)

A base HTTP Command, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a command*).

It also implements a `ProfileableInterface` feature.

MethodTypeDescription`getRequestType`**final**It declares a request type of a Http command to be a `Psr\Http\Message\RequestInterface``getHttpMethod`abstractIt requires a command to return a http method of a command. (see [PSR Http Message Util](https://github.com/php-fig/http-message-util))`getUri`abstractThis method returns a URI of the Command - it may be just a `string` or a `Psr\Http\Message\UriInterface` (PSR-7) instance.`modifyRequest`*base*If you overwrite this method, you can manipulate a `RequestInterface` instance.`getProfilerId`*base*It's a predefined creating of profiler id for a http command. It creates a profiler id based on `http method` and `uri`.`getProfilerData`*base*If you overwrite this method, you can specify additional profiler data. Default is `null` (*no data*).`__toString`*base*It's a predefined casting a Command into string, it returns a string representation of `uri`.### AbstractHttpDeleteCommand

[](#abstracthttpdeletecommand)

A base HTTP **DELETE** Command, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a command*).

It extends a base `AbstractHttpCommand` and predefine some abstract methods.

MethodTypeDescription`getHttpMethod`**final**It declares a http method of this query to be `DELETE`.### AbstractHttpPatchCommand

[](#abstracthttppatchcommand)

A base HTTP **PATCH** Command, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a command*).

It extends a base `AbstractHttpCommand` and predefine some abstract methods.

MethodTypeDescription`getHttpMethod`**final**It declares a http method of this query to be `PATCH`.### AbstractHttpPostCommand

[](#abstracthttppostcommand)

A base HTTP **POST** Command, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a command*).

It extends a base `AbstractHttpCommand` and predefine some abstract methods.

MethodTypeDescription`getHttpMethod`**final**It declares a http method of this query to be `POST`.`createBody`abstractIt requires a command to return an instance of `Psr\Http\Message\StreamInterface` which is used as a POST request body.`createRequest`*base*It creates a request with a body.`getProfilerData`*base*It adds a `Body` into additional data for profiler, so it may be shown later in profiler.### AbstractHttpPutCommand

[](#abstracthttpputcommand)

A base HTTP **PATCH** Command, it abstracts a creating of a `Psr\Http\Message\RequestInterface` (PSR-7) using a `Psr\Http\Message\RequestFactoryInterface` (PSR-17) (*it is directly required to be injected into a command*).

It extends a base `AbstractHttpCommand` and predefine some abstract methods.

MethodTypeDescription`getHttpMethod`**final**It declares a http method of this query to be `PATCH`.Send Command Handlers
---------------------

[](#send-command-handlers)

It is responsible for handling a specific Command request and passing a result into `OnSuccess` callback. [See more here](https://github.com/lmc-eu/cqrs-types#send-command-handler-interface).

### Http Send Command Handler

[](#http-send-command-handler)

This handler supports `Psr\Http\Message\RequestInterface` and handles it into `Psr\Http\Message\ResponseInterface`.

It also checks a status code of a response and marks it as error if it is an error code:

- 400 -&gt; `HttpBadRequestException`
- 500 -&gt; `HttpServerErrorException`

---

Response Decoders
-----------------

[](#response-decoders)

It is meant to decode a response (a result of either `QueryHandlerInterface` or a `SendCommandHandlerInterface`). [See more here](https://github.com/lmc-eu/cqrs-types#response-decoder-interface).

### HttpMessageResponseDecoder

[](#httpmessageresponsedecoder)

It decodes a `Psr\Http\Message\ResponseInterface` into a `Psr\Http\Message\StreamInterface` by getting a body of a response.

### StreamResponseDecoder

[](#streamresponsedecoder)

It decodes a `Psr\Http\Message\StreamInterface` into a `string` by getting a stream contents (*if possible*).

**Note**: There is also a [JsonResponseDecoder](https://github.com/lmc-eu/cqrs-types#jsonresponsedecoder) which decodes a string into an array.

Profiler Formatters
-------------------

[](#profiler-formatters)

### HttpProfilerFormatter

[](#httpprofilerformatter)

It formats a `Psr\Http\Message\MessageInterface` and `Psr\Http\Message\StreamInterface` into a readable format, so a data is nicer in profiler.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~342 days

Total

4

Last Release

803d ago

Major Versions

1.0.0 → 2.0.02021-08-10

2.0.0 → 3.0.02022-04-27

PHP version history (3 changes)1.0.0PHP ^7.4

3.0.0PHP ^8.1

3.1.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bdf0b9957c08a48e70a52fce74fc4f1add30b12d442450d5e2b48854fc98b21?d=identicon)[MortalFlesh](/maintainers/MortalFlesh)

---

Top Contributors

[![MortalFlesh](https://avatars.githubusercontent.com/u/6317184?v=4)](https://github.com/MortalFlesh "MortalFlesh (20 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lmc-cqrs-http/health.svg)

```
[![Health](https://phpackages.com/badges/lmc-cqrs-http/health.svg)](https://phpackages.com/packages/lmc-cqrs-http)
```

###  Alternatives

[kreait/firebase-php

Firebase Admin SDK

2.4k39.7M72](/packages/kreait-firebase-php)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[swisnl/json-api-client

A PHP package for mapping remote JSON:API resources to Eloquent like models and collections.

211473.2k12](/packages/swisnl-json-api-client)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
