GuzzleHttp\Client::__construct PHP Method

__construct() public method

Here's an example of creating a client using a base_uri and an array of default request options to apply to each request: $client = new Client([ 'base_uri' => 'http://www.foo.com/1.0/', 'timeout' => 0, 'allow_redirects' => false, 'proxy' => '192.168.16.1:10' ]); Client configuration settings include the following options: - handler: (callable) Function that transfers HTTP requests over the wire. The function is called with a Psr7\Http\Message\RequestInterface and array of transfer options, and must return a GuzzleHttp\Promise\PromiseInterface that is fulfilled with a Psr7\Http\Message\ResponseInterface on success. "handler" is a constructor only option that cannot be overridden in per/request options. If no handler is provided, a default handler will be created that enables all of the request options below by attaching all of the default middleware to the handler. - base_uri: (string|UriInterface) Base URI of the client that is merged into relative URIs. Can be a string or instance of UriInterface. - **: any request option
See also: GuzzleHttp\RequestOptions for a list of available request options.
public __construct ( array $config = [] )
$config array Client configuration settings.
    public function __construct(array $config = [])
    {
        if (!isset($config['handler'])) {
            $config['handler'] = HandlerStack::create();
        }
        // Convert the base_uri to a UriInterface
        if (isset($config['base_uri'])) {
            $config['base_uri'] = Psr7\uri_for($config['base_uri']);
        }
        $this->configureDefaults($config);
    }

Usage Example

 /**
  * Constructor.
  * 
  * @param string $xApiKey
  *   An api.data.gov api key that is granted to your user.
  *
  * @param string $xAdminAuthToken
  *   Admin Authorization Token provided by api.data.gov admin accounts.
  */
 public function __construct($xApiKey, $xAdminAuthToken)
 {
     parent::__construct(['base_url' => $this->apiUrl]);
     $this->xApiKey = $xApiKey;
     $this->xAdminAuthToken = $xAdminAuthToken;
     $this->setDefaultOption('headers', array('X-Api-Key' => $this->xApiKey, 'X-Admin-Auth-Token' => $this->xAdminAuthToken, 'Content-Type' => 'application/json', 'Accept' => 'text/*'));
 }
All Usage Examples Of GuzzleHttp\Client::__construct