class ResourceResponse

Same name in this branch
  1. 11.x core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
Same name in other branches
  1. 9 core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  2. 9 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
  3. 8.9.x core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  4. 8.9.x core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse
  5. 10 core/modules/jsonapi/src/ResourceResponse.php \Drupal\jsonapi\ResourceResponse
  6. 10 core/modules/rest/src/ResourceResponse.php \Drupal\rest\ResourceResponse

Contains data for serialization before sending the response.

We do not want to abuse the $content property on the Response class to store our response data. $content implies that the provided data must either be a string or an object with a __toString() method, which is not a requirement for data used here.

Routes that return this response must specify the '_format' requirement.

Hierarchy

Expanded class hierarchy of ResourceResponse

See also

\Drupal\rest\ModifiedResourceResponse

6 files declare their use of ResourceResponse
DbLogResource.php in core/modules/dblog/src/Plugin/rest/resource/DbLogResource.php
EntityResource.php in core/modules/rest/src/Plugin/rest/resource/EntityResource.php
NoSerializationClassTestResource.php in core/modules/rest/tests/modules/rest_test/src/Plugin/rest/resource/NoSerializationClassTestResource.php
RequestHandlerTest.php in core/modules/rest/tests/src/Kernel/RequestHandlerTest.php
ResourceResponseSubscriberTest.php in core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php

... See full list

File

core/modules/rest/src/ResourceResponse.php, line 21

Namespace

Drupal\rest
View source
class ResourceResponse extends Response implements CacheableResponseInterface, ResourceResponseInterface {
    use CacheableResponseTrait;
    use ResourceResponseTrait;
    
    /**
     * Constructor for ResourceResponse objects.
     *
     * @param mixed $data
     *   Response data that should be serialized.
     * @param int $status
     *   The response status code.
     * @param array $headers
     *   An array of response headers.
     */
    public function __construct($data = NULL, $status = 200, $headers = []) {
        $this->responseData = $data;
        parent::__construct('', $status, $headers);
    }

}

Members

Title Sort descending Modifiers Object type Summary
CacheableResponseTrait::$cacheabilityMetadata protected property The cacheability metadata.
CacheableResponseTrait::addCacheableDependency public function
CacheableResponseTrait::getCacheableMetadata public function
ResourceResponse::__construct public function Constructor for ResourceResponse objects.
ResourceResponseTrait::$responseData protected property Response data that should be serialized.
ResourceResponseTrait::getResponseData public function Returns response data that should be serialized.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.