public function DeployServicesClient::request in Deploy Services Client 7
Performs a request to a REST path on the endpoint.
Parameters
$path: The path (relative to the endpoint URL) to request.
$method: The HTTP method (e.g., 'GET' or 'DELETE') for the request.
$data: (Optional) A string containing the data to send (e.g., for a 'PUT' request). If not provided, no data will be sent.
Return value
The drupal_http_request() response object returned from the request.
Throws
See also
DeployServiceRestJSON::deploy()
DeployServiceRest::httpRequest()
1 call to DeployServicesClient::request()
- DeployServicesClient::entityRequest in ./
deploy_services_client.client.inc - Performs a request to the endpoint to perform an action on an entity.
File
- ./
deploy_services_client.client.inc, line 287 - Defines a Services client class which communicates with Deployment endpoints.
Class
- DeployServicesClient
- Class which defines a Services client based on a Deployment endpoint.
Code
public function request($path, $method, $data = NULL) {
$url = $this->endpoint->service_config['url'] . '/' . $path;
$headers['Content-Type'] = 'application/json';
// Make the request as an authenticated user if we are already logged in to
// the endpoint.
if ($this->loginCookie) {
$headers['Cookie'] = $this->loginCookie;
$headers['X-CSRF-Token'] = $this->tokenResponse;
}
$options = array(
'method' => $method,
'headers' => $headers,
'data' => $data,
);
if ($this
->debugEnabled()) {
watchdog('deploy_services_client', 'Service request: %url <pre>@options</pre>', array(
'%url' => $url,
'@options' => print_r($options, TRUE),
), WATCHDOG_DEBUG);
}
// Perform the request.
$response = drupal_http_request($url, $options);
if ($this
->debugEnabled()) {
watchdog('deploy_services_client', 'Service response: <pre>@response</pre>', array(
'@response' => print_r($response, TRUE),
), WATCHDOG_DEBUG);
}
if (isset($response->error) || !in_array($response->code, array(
200,
304,
))) {
throw new DeployServiceException(t('Service error: @code @error', array(
'@code' => $response->code,
'@error' => $response->error,
)));
}
return $response;
}