JsonEncodeResponse
A JSON PSR-7 response implementation.
Allows creating a response by passing data to the constructor; by default, serializes the data to JSON, sets a status code of 200 and sets the Content-Type header to application/json.
- Full name:
\Drupal\helper\Response\JsonEncodeResponse - Parent class:
Response
Methods
__construct
{@inheritdoc}
public __construct(mixed $data, int $status = 200, array $headers = [], string $version = '1.1', string|null $reason = null): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$data |
mixed | |
| The data to be JSON encoded in the response. | ||
$status |
int | |
| Status code. | ||
$headers |
array | |
| Response headers. | ||
$version |
string | |
| Protocol version. | ||
$reason |
string|null | |
| Reason phrase (when empty a default will be used based on the status | ||
| code). |
Throws:
If an error happened while encoding $data into JSON.
- JsonException