Defining a PSR-7 Response class
The Response class represents outbound information returned to whatever entity made the original request. HTTP headers play an important role in this context as we need to know that format is requested by the client, usually in the incoming Accept
header. We then need to set the appropriate Content-Type
header in the Response class to match that format. Otherwise, the actual body of the response will be HTML, JSON, or whatever else has been requested (and delivered).
How to do it...
- The
Response
class is actually much easier to implement than theRequest
class as we are only concerned with returning the response from the server to the client. Additionally, it extends ourApplication\MiddleWare\Message
class where ...
Get PHP 7 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.