Properties

$config

$config : array

Type

array — Default request options

Methods

__construct()

__construct(array  $config = array()) 

Clients accept an array of constructor parameters.

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

Parameters

array $config

Client configuration settings.

__call()

__call(  $method,   $args) 

Parameters

$method
$args

sendAsync()

sendAsync(\Psr\Http\Message\RequestInterface  $request, array  $options = array()) : \GuzzleHttp\Promise\PromiseInterface

Asynchronously send an HTTP request.

Parameters

\Psr\Http\Message\RequestInterface $request

Request to send

array $options

Request options to apply to the given request and to the transfer.

Returns

\GuzzleHttp\Promise\PromiseInterface

requestAsync()

requestAsync(string  $method, string|\Psr\Http\Message\UriInterface  $uri = '', array  $options = array()) : \GuzzleHttp\Promise\PromiseInterface

Create and send an asynchronous HTTP request.

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters

string $method

HTTP method

string|\Psr\Http\Message\UriInterface $uri

URI object or string.

array $options

Request options to apply.

Returns

\GuzzleHttp\Promise\PromiseInterface

request()

request(string  $method, string|\Psr\Http\Message\UriInterface  $uri = '', array  $options = array()) : \Psr\Http\Message\ResponseInterface

Create and send an HTTP request.

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters

string $method

HTTP method.

string|\Psr\Http\Message\UriInterface $uri

URI object or string.

array $options

Request options to apply.

Returns

\Psr\Http\Message\ResponseInterface

getConfig()

getConfig(string|null  $option = null) : mixed

Get a client configuration option.

These options include default request options of the client, a "handler" (if utilized by the concrete client), and a "base_uri" if utilized by the concrete client.

Parameters

string|null $option

The config option to retrieve.

Returns

mixed

get()

get(string|\UriInterface  $uri, array  $options = []) : \Psr\Http\Message\ResponseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\Psr\Http\Message\ResponseInterface

head()

head(string|\UriInterface  $uri, array  $options = []) : \Psr\Http\Message\ResponseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\Psr\Http\Message\ResponseInterface

put()

put(string|\UriInterface  $uri, array  $options = []) : \Psr\Http\Message\ResponseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\Psr\Http\Message\ResponseInterface

post()

post(string|\UriInterface  $uri, array  $options = []) : \Psr\Http\Message\ResponseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\Psr\Http\Message\ResponseInterface

patch()

patch(string|\UriInterface  $uri, array  $options = []) : \Psr\Http\Message\ResponseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\Psr\Http\Message\ResponseInterface

delete()

delete(string|\UriInterface  $uri, array  $options = []) : \Psr\Http\Message\ResponseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\Psr\Http\Message\ResponseInterface

getAsync()

getAsync(string|\UriInterface  $uri, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

headAsync()

headAsync(string|\UriInterface  $uri, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

putAsync()

putAsync(string|\UriInterface  $uri, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

postAsync()

postAsync(string|\UriInterface  $uri, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

patchAsync()

patchAsync(string|\UriInterface  $uri, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

deleteAsync()

deleteAsync(string|\UriInterface  $uri, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Parameters

string|\UriInterface $uri
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

buildUri()

buildUri(  $uri, array  $config) 

Parameters

$uri
array $config

configureDefaults()

configureDefaults(array  $config) 

Configures the default options for a client.

Parameters

array $config

prepareDefaults()

prepareDefaults(array  $options) : array

Merges default options into the array.

Parameters

array $options

Options to modify by reference

Returns

array

transfer()

transfer(\Psr\Http\Message\RequestInterface  $request, array  $options) : \GuzzleHttp\Promise\PromiseInterface

Transfers the given request and applies request options.

The URI of the request is not modified and the request options are used as-is without merging in default options.

Parameters

\Psr\Http\Message\RequestInterface $request
array $options

Returns

\GuzzleHttp\Promise\PromiseInterface

invalidBody()

invalidBody()