You are here

protected function SolrConnectorPluginBase::restRequest in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()
  2. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()
  3. 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()

Sends a REST request to the Solr server endpoint and returns the result.

Parameters

string $handler: The handler used for the API query.

string $method: The HTTP request method.

string $command_json: The command to send encoded as JSON.

Return value

array The decoded response.

Throws

\Drupal\search_api_solr\SearchApiSolrException

4 calls to SolrConnectorPluginBase::restRequest()
SolrConnectorPluginBase::coreRestGet in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST GET request to the Solr core and returns the result.
SolrConnectorPluginBase::coreRestPost in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST POST request to the Solr core and returns the result.
SolrConnectorPluginBase::serverRestGet in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST GET request to the Solr server and returns the result.
SolrConnectorPluginBase::serverRestPost in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST POST request to the Solr server and returns the result.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 669

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

protected function restRequest($handler, $method = Request::METHOD_GET, $command_json = '') {
  $this
    ->connect();
  $query = $this->solr
    ->createApi([
    'handler' => $handler,
    'accept' => 'application/json',
    'contenttype' => 'application/json',
    'method' => $method,
    'rawdata' => Request::METHOD_POST == $method ? $command_json : NULL,
  ]);
  $response = $this
    ->execute($query);
  $output = $response
    ->getData();

  // \Drupal::logger('search_api_solr')->info(print_r($output, true));.
  if (!empty($output['errors'])) {
    throw new SearchApiSolrException('Error trying to send a REST request.' . "\nError message(s):" . print_r($output['errors'], TRUE));
  }
  return $output;
}