Documentation

Client
in package
implements ClientInterface, ClientInterface Uses ClientTrait

Tags
final

Interfaces, Classes, Traits and Enums

ClientInterface
Client interface for sending HTTP requests.
ClientInterface

Table of Contents

$config  : array<string|int, mixed>
__call()  : PromiseInterface|ResponseInterface
__construct()  : mixed
Clients accept an array of constructor parameters.
delete()  : ResponseInterface
Create and send an HTTP DELETE request.
deleteAsync()  : PromiseInterface
Create and send an asynchronous HTTP DELETE request.
get()  : ResponseInterface
Create and send an HTTP GET request.
getAsync()  : PromiseInterface
Create and send an asynchronous HTTP GET request.
getConfig()  : mixed
Get a client configuration option.
head()  : ResponseInterface
Create and send an HTTP HEAD request.
headAsync()  : PromiseInterface
Create and send an asynchronous HTTP HEAD request.
patch()  : ResponseInterface
Create and send an HTTP PATCH request.
patchAsync()  : PromiseInterface
Create and send an asynchronous HTTP PATCH request.
post()  : ResponseInterface
Create and send an HTTP POST request.
postAsync()  : PromiseInterface
Create and send an asynchronous HTTP POST request.
put()  : ResponseInterface
Create and send an HTTP PUT request.
putAsync()  : PromiseInterface
Create and send an asynchronous HTTP PUT request.
request()  : ResponseInterface
Create and send an HTTP request.
requestAsync()  : PromiseInterface
Create and send an asynchronous HTTP request.
send()  : ResponseInterface
Send an HTTP request.
sendAsync()  : PromiseInterface
Asynchronously send an HTTP request.
sendRequest()  : ResponseInterface
The HttpClient PSR (PSR-18) specify this method.
applyOptions()  : RequestInterface
Applies the array of request options to a request.
buildUri()  : UriInterface
configureDefaults()  : void
Configures the default options for a client.
invalidBody()  : InvalidArgumentException
Return an InvalidArgumentException with pre-set message.
prepareDefaults()  : array<string|int, mixed>
Merges default options into the array.
transfer()  : PromiseInterface
Transfers the given request and applies request options.

Properties

$config

private array<string|int, mixed> $config

Default request options

Methods

__construct()

Clients accept an array of constructor parameters.

public __construct([array<string|int, mixed> $config = [] ]) : mixed

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. 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
$config : array<string|int, mixed> = []

Client configuration settings.

Tags
see
RequestOptions

for a list of available request options.

Return values
mixed

delete()

Create and send an HTTP DELETE request.

public delete(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

deleteAsync()

Create and send an asynchronous HTTP DELETE request.

public deleteAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

get()

Create and send an HTTP GET request.

public get(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

getAsync()

Create and send an asynchronous HTTP GET request.

public getAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

getConfig()

Get a client configuration option.

public getConfig([string|null $option = null ]) : mixed

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
$option : string|null = null

The config option to retrieve.

Tags
deprecated

Client::getConfig will be removed in guzzlehttp/guzzle:8.0.

Return values
mixed

head()

Create and send an HTTP HEAD request.

public head(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

headAsync()

Create and send an asynchronous HTTP HEAD request.

public headAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

patch()

Create and send an HTTP PATCH request.

public patch(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

patchAsync()

Create and send an asynchronous HTTP PATCH request.

public patchAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

post()

Create and send an HTTP POST request.

public post(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

postAsync()

Create and send an asynchronous HTTP POST request.

public postAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

put()

Create and send an HTTP PUT request.

public put(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

putAsync()

Create and send an asynchronous HTTP PUT request.

public putAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

request()

Create and send an HTTP request.

public request(string $method[, string|UriInterface $uri = '' ][, array<string|int, mixed> $options = [] ]) : ResponseInterface

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
$method : string

HTTP method.

$uri : string|UriInterface = ''

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply. See \GuzzleHttp\RequestOptions.

Tags
throws
GuzzleException
Return values
ResponseInterface

requestAsync()

Create and send an asynchronous HTTP request.

public requestAsync(string $method[, string|UriInterface $uri = '' ][, array<string|int, mixed> $options = [] ]) : PromiseInterface

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
$method : string

HTTP method

$uri : string|UriInterface = ''

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply. See \GuzzleHttp\RequestOptions.

Return values
PromiseInterface

sendAsync()

Asynchronously send an HTTP request.

public sendAsync(RequestInterface $request[, array<string|int, mixed> $options = [] ]) : PromiseInterface
Parameters
$request : RequestInterface

Request to send

$options : array<string|int, mixed> = []

Request options to apply to the given request and to the transfer. See \GuzzleHttp\RequestOptions.

Return values
PromiseInterface

configureDefaults()

Configures the default options for a client.

private configureDefaults(array<string|int, mixed> $config) : void
Parameters
$config : array<string|int, mixed>
Return values
void

prepareDefaults()

Merges default options into the array.

private prepareDefaults(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

Options to modify by reference

Return values
array<string|int, mixed>

transfer()

Transfers the given request and applies request options.

private transfer(RequestInterface $request, array<string|int, mixed> $options) : PromiseInterface

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

Parameters
$request : RequestInterface
$options : array<string|int, mixed>

See \GuzzleHttp\RequestOptions.

Return values
PromiseInterface

Search results