send() public method

Aggregates read and write methods into a coherent request response
public send ( Message $message = null, array $options = [] ) : object
$message Message
$options array - '`response`': a fully-namespaced string for the response object
return object a response object based on `\lithium\net\Message`
Example #1
0
 /**
  * Send request and return response data.
  *
  * @param string $method
  * @param string $path
  * @param array $data
  * @param array $options
  * @return string
  */
 public function send($method, $path = null, $data = null, $options = array())
 {
     $defaults = array('return' => 'body');
     $options += $defaults;
     if (!$this->connect()) {
         return;
     }
     $request = $this->_request($method, $path, $data, $options);
     $response = $this->_connection->send($request, array('classes' => $this->_classes));
     if ($response) {
         $this->last = (object) compact('request', 'response');
         $this->disconnect();
         return $options['return'] == 'body' ? $response->body() : $response;
     }
 }