function RestExampleClientCalls::delete

Same name in other branches
  1. 3.x modules/rest_example/src/RestExampleClientCalls.php \Drupal\rest_example\RestExampleClientCalls::delete()

Delete a node on the remote server, using DELETE.

You are encouraged to read the code and the comments in RestExampleClientCalls::create() first.

Parameters

array $node: Contains the data of the node we want to create.

Return value

\Symfony\Component\HttpFoundation\Response An HTTP response.

Throws

\InvalidArgumentException

\GuzzleHttp\Exception\GuzzleException

File

modules/rest_example/src/RestExampleClientCalls.php, line 216

Class

RestExampleClientCalls
Here we interact with the remote service.

Namespace

Drupal\rest_example

Code

public function delete(array $node) {
    if (empty($this->remoteUrl)) {
        return new Response('The remote URL has not been setup.', 500);
    }
    $response = $this->client
        ->request('DELETE', $this->remoteUrl . '/node/' . $node['nid'], [
        'headers' => $this->clientHeaders,
        'auth' => $this->clientAuth,
    ]);
    if ($response->getStatusCode() != 204) {
        return new Response('An error occurred while patching the node.', 500);
    }
    return $response;
}