Instantiates a request object (usually an instance of `http\Request`) and tests its properties based on the request type and data to be sent.

Parameters

  • string $method The HTTP method of the request, i.e. `'GET'`, `'HEAD'`, `'OPTIONS'`, etc. Can be passed in upper- or lower-case.
  • string $path The
  • string $data
  • string $options

Returns

object Returns an instance of `http\Request`, configured with an HTTP method, query string or POST/PUT data, and URL.

Source

						protected function _request($method, $path, $data, $options) {
		$defaults = array('type' => 'form');
		$options += $defaults + $this->_config;
		$request = $this->_instance('request', $options);
		$request->path = str_replace('//', '/', "{$request->path}{$path}");
		$request->method = $method = strtoupper($method);
		$hasBody = in_array($method, array('POST', 'PUT'));

		$media = $this->_classes['media'];
		$type = null;

		if ($data && in_array($options['type'], $media::types())) {
			$type = $media::type($options['type']);
			$contentType = (array) $type['content'];
			$request->headers(array('Content-Type' => current($contentType)));
			$data = $hasBody && !is_string($data) ?
				Media::encode($options['type'], $data, $options) : $data;
		}
		$hasBody ? $request->body($data) : $request->query = $data;
		return $request;
	}