1. 8.5.x core/modules/rest/src/ModifiedResourceResponse.php
  2. 8.2.x core/modules/rest/src/ModifiedResourceResponse.php
  3. 8.3.x core/modules/rest/src/ModifiedResourceResponse.php
  4. 8.4.x core/modules/rest/src/ModifiedResourceResponse.php
  5. 8.6.x core/modules/rest/src/ModifiedResourceResponse.php

Namespace

Drupal\rest

File

core/modules/rest/src/ModifiedResourceResponse.php
View source
<?php

namespace Drupal\rest;

use Symfony\Component\HttpFoundation\Response;

/**
 * A response that does not contain cacheability metadata.
 *
 * Used when resources are modified by a request: responses to unsafe requests
 * (POST/PATCH/DELETE) can never be cached.
 *
 * @see \Drupal\rest\ResourceResponse
 */
class ModifiedResourceResponse extends Response implements ResourceResponseInterface {
  use ResourceResponseTrait;

  /**
   * Constructor for ModifiedResourceResponse 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);
  }

}

Classes

Namesort descending Description
ModifiedResourceResponse A response that does not contain cacheability metadata.

Comments

redbrickone’s picture

If you are using a custom endpoint to POST or PATCH data, you need to return a ModifiedResourceResponse rather than a ResourceResponse. If you do not, you will get a 500 error bc it tries to cache the metadata you are POSTing.