1.2.1. Overview

The Sapien Response is a mutable object representing the PHP response to be sent from the server.

It provides a retention space for the HTTP response version, code, headers, cookies, and content, so they can be inspected before sending.

Use a Response in place of the header(), setcookie(), setrawcookie(), etc. functions. Instantiation

Instantation is straightforward:

use Sapien\Response;

$response = new Response(); Examples

Here are some basic examples of creating and sending a response:

// a "200 OK" response with some body content:
    ->setHeader('content-type', 'text/plain')
    ->setContent('Hello World!')

// a "303 See Other" response
    ->setHeader('location', '/path/to/resource')

// sending a cookie with the response; note how the setter methods
// are fluent, allowing you to chain calls to the Response
    ->setCookie(name: 'foo', value: 'bar')
    ->setContent("Cookie has been set!")
    ->send(); Further Reading

The Response provides public methods related to these areas:

You can extend the Response for your own purposes, though you should check out one of the specialized responses before doing so.