Client
in package
implements
ClientInterface, ClientInterface
uses
ClientTrait
Tags
Table of Contents
Interfaces
- ClientInterface
- Client interface for sending HTTP requests.
- ClientInterface
Properties
- $config : array<string|int, mixed>
Methods
- __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
__call()
public
__call(string $method, array<string|int, mixed> $args) : PromiseInterface|ResponseInterface
Client::__call will be removed in guzzlehttp/guzzle:8.0.
Parameters
- $method : string
- $args : array<string|int, mixed>
Return values
PromiseInterface|ResponseInterface__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
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
Return values
ResponseInterfacedeleteAsync()
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
PromiseInterfaceget()
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
Return values
ResponseInterfacegetAsync()
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
PromiseInterfacegetConfig()
Get a client configuration option.
public
getConfig([string|null $option = null ]) : mixed
Client::getConfig will be removed in guzzlehttp/guzzle:8.0.
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.
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
Return values
ResponseInterfaceheadAsync()
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
PromiseInterfacepatch()
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
Return values
ResponseInterfacepatchAsync()
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
PromiseInterfacepost()
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
Return values
ResponseInterfacepostAsync()
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
PromiseInterfaceput()
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
Return values
ResponseInterfaceputAsync()
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
PromiseInterfacerequest()
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
Return values
ResponseInterfacerequestAsync()
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
PromiseInterfacesend()
Send an HTTP request.
public
send(RequestInterface $request[, array<string|int, mixed> $options = [] ]) : ResponseInterface
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.
Tags
Return values
ResponseInterfacesendAsync()
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
PromiseInterfacesendRequest()
The HttpClient PSR (PSR-18) specify this method.
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterfaceapplyOptions()
Applies the array of request options to a request.
private
applyOptions(RequestInterface $request, array<string|int, mixed> &$options) : RequestInterface
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
Return values
RequestInterfacebuildUri()
private
buildUri(UriInterface $uri, array<string|int, mixed> $config) : UriInterface
Parameters
- $uri : UriInterface
- $config : array<string|int, mixed>
Return values
UriInterfaceconfigureDefaults()
Configures the default options for a client.
private
configureDefaults(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
invalidBody()
Return an InvalidArgumentException with pre-set message.
private
invalidBody() : InvalidArgumentException
Return values
InvalidArgumentExceptionprepareDefaults()
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.