You are here

public function JsonEncodeResponse::__construct in Helper 8

Parameters

mixed $data: The data to be JSON encoded in the response.

int $status: Status code.

array $headers: Response headers.

string $version: Protocol version.

string|null $reason: Reason phrase (when empty a default will be used based on the status code).

File

src/Response/JsonEncodeResponse.php, line 31

Class

JsonEncodeResponse
A JSON PSR-7 response implementation.

Namespace

Drupal\helper\Response

Code

public function __construct($data, $status = 200, array $headers = [], $version = '1.1', $reason = NULL) {
  $body = \GuzzleHttp\json_encode($data);
  $headers += [
    'Content-Type' => 'application/json',
  ];
  parent::__construct($status, $headers, $body, $version, $reason);
}