lmc / cqrs-http
A library containing base implementations to help with Http Queries and Commands
Installs: 17 252
Dependents: 2
Suggesters: 1
Security: 0
Stars: 1
Watchers: 14
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- ext-json: *
- ext-mbstring: *
- fig/http-message-util: ^1.1
- lmc/cqrs-types: ^3.2
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.5
- guzzlehttp/psr7: ^2.1
- lmc/coding-standard: ^3.3
- nyholm/psr7: ^1.4
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^11.0.4
README
A library containing base implementations to help with Http Queries and Commands. This library is an extension for CQRS/Bundle and adds support for PSR-7.
Table of contents
- Installation
- Queries
- Commands
- Response Decoders
- Profiler Formatters
Installation
composer require lmc/cqrs-http
NOTE: You will also need an implementation for PSR-7, PSR-17 and PSR-18 for HTTP extensions to work.
Query
Query is a request which fetch a data without changing anything. See more here
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.
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
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
It is responsible for handling a specific Query request and passing a result into OnSuccess
callback. See more here.
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 ->
HttpBadRequestException
- 500 ->
HttpServerErrorException
Command
Command is a request which change a data and may return result data. See more here
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.
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.
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.
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.
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.
Send Command Handlers
It is responsible for handling a specific Command request and passing a result into OnSuccess
callback. See more here.
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 ->
HttpBadRequestException
- 500 ->
HttpServerErrorException
Response Decoders
It is meant to decode a response (a result of either QueryHandlerInterface
or a SendCommandHandlerInterface
). See more here.
HttpMessageResponseDecoder
It decodes a Psr\Http\Message\ResponseInterface
into a Psr\Http\Message\StreamInterface
by getting a body of a response.
StreamResponseDecoder
It decodes a Psr\Http\Message\StreamInterface
into a string
by getting a stream contents (if possible).
Note: There is also a JsonResponseDecoder which decodes a string into an array.
Profiler Formatters
HttpProfilerFormatter
It formats a Psr\Http\Message\MessageInterface
and Psr\Http\Message\StreamInterface
into a readable format, so a data is nicer in profiler.