lmc/cqrs-http

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

3.1.0 2024-03-06 13:08 UTC

This package is auto-updated.

Last update: 2024-12-06 15:01:47 UTC


README

cqrs-types Latest Stable Version Tests and linting Coverage Status

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

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.