PSR 7 Messages - airtype/craft-httpmessages GitHub Wiki

What is PSR-7?

[PSR-7] (http://www.php-fig.org/psr/psr-7/) is an standard regarding HTTP message interfaces as defined by [PHP-FIG] (http://www.php-fig.org/), a group dedicated to defining common interfaces that can be utilized by any php framework, package or project.

By utilizing request and response objects that implement these interfaces, developers have a consistent way of accessing or request/response properties. In addition to directly utilizing these objects, developers can easily implement with a variety third-party packages that are also coded to these interfaces. [Zend Diactoros] (https://github.com/zendframework/zend-diactoros) is used to generate the request and response objects. [Relay] (http://relayphp.com) and PSR-7 Middlewares are utilized to handle the request and response objects.

What are messages?

Consider a postal courier. A courier is responsible for facilitating the transfer of letters. A letter could be an invitation to an event. Another letter could be the response to an invitation.

In this analogy, HTTP is like the postal courier. HTTP is responsible for delivering HTTP messages, much like the courier delivering letters. There can be a variety of message types. There can be requests, responses, or even specific types of requests or responses.

PSR-7 aims consider any form of communication a message. Requests and responses are two types of messages. Message types can also be extended. For example, a server request is a particular type of request.

This plugin creates base Request, ServerRequest and Response objects that implement the PSR-7 interfaces. In addition, this plugin extends a ServerRequest as a HttpMessages_CraftRequest object, adding Craft specific properties and methods to the ServerRequest object. Likewise, the Response object is also extended as a HttpMessages_CraftResponse object.