class 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
- class \Drupal\rest\ResourceResponse implements \Drupal\Core\Cache\CacheableResponseInterface, \Drupal\rest\ResourceResponseInterface uses \Drupal\Core\Cache\CacheableResponseTrait, \Drupal\rest\ResourceResponseTrait extends \Symfony\Component\HttpFoundation\Response
 
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  
File
- 
              core/
modules/ rest/ src/ ResourceResponse.php, line 21  
Namespace
Drupal\restView 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.