Skip to content

Latest commit

 

History

History
executable file
·
49 lines (32 loc) · 1.48 KB

httpmessages.rst

File metadata and controls

executable file
·
49 lines (32 loc) · 1.48 KB

HTTP Messages

HTTP Messages

The LightMVC Framework's HTTP message objects are the \Zend\Diactoros\ServerRequest and the \Zend\Diactoros\Response objects. These are PSR-7 compliant classes and are compatible with PSR-15 compliant middleware.

Request

ServerRequest Object

In order to get a better understanding of the ServerRequest object, please see the ZF documentation on server-side applications.

Response

Response Object

The Response object makes it possible to add headers and provide content to the application's final response to the client. Here is a simple example in order to do so:

$response = new Zend\Diactoros\Response();

// Write to the response body:
$response->getBody()->write("Hello");

// Multiple calls to write() append:
$response->getBody()->write(" World"); // now "Hello World"

// Add headers
// Note: headers can be added to the response after the data has been written to the body
$response = $response
    ->withHeader('Content-Type', 'text/plain')
    ->withAddedHeader('X-Custom-Header', 'example');

For further reading on the Response object, please see the ZF documentation.