protected function SolrConnectorPluginBase::restRequest in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()
- 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()
- 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 $endpoint_key: The endpoint that refelcts the base URI.
string $path: The path to append to the base URI.
string $method: The HTTP request method.
string $command_json: The command to send encoded as JSON.
Return value
string The decoded response.
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 636
Class
- SolrConnectorPluginBase
- Defines a base class for Solr connector plugins.
Namespace
Drupal\search_api_solr\SolrConnectorCode
protected function restRequest($endpoint_key, $path, $method = Request::METHOD_GET, $command_json = '') {
$this
->connect();
$request = new Request();
$request
->setMethod($method);
$request
->addHeader('Accept: application/json');
if (Request::METHOD_POST == $method) {
$request
->addHeader('Content-Type: application/json');
$request
->setRawData($command_json);
}
$request
->setHandler($path);
$endpoint = $this->solr
->getEndpoint($endpoint_key);
$timeout = $endpoint
->getTimeout();
// @todo Destinguish between different flavors of REST requests and use
// different timeout settings.
$endpoint
->setTimeout($this->configuration['optimize_timeout']);
$response = $this
->executeRequest($request, $endpoint);
$endpoint
->setTimeout($timeout);
$output = Json::decode($response
->getBody());
// \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;
}