Composer package for Laravel 5.0 and above that provides a consistent method of interacting with Guzzle.
This package is intended to be used to interact with JSON web services but it can also be used with any kind of request endpoint. It provides a basic interface with which to make requests but there is also the option to interact with the underlying Guzzle client instance directly if you need more robust functionality.
NOTE: If your Laravel version is above 5.4, Guzzle may not be included by default. Check your vendor
directory to verify. If you do not have a Guzzle dependency, run this command first:
composer require guzzlehttp/guzzle:~6.0
To install this package from Composer, use the following command:
composer require csun-metalab/laravel-guzzle
Add the service provider to your providers
array in config/app.php
in Laravel as follows:
'providers' => [
//...
CSUNMetaLab\Guzzle\Providers\GuzzleServiceProvider::class,
// You can also use this based on Laravel convention:
// 'CSUNMetaLab\Guzzle\Providers\GuzzleServiceProvider',
//...
],
Finally, run the following Artisan command to publish everything:
php artisan vendor:publish
The following assets are published:
- Configuration (tagged as
config
) - these go into yourconfig
directory
There are currently no required environment variables but there are optional environment variables.
This is the authentication username that will be used for all default Guzzle requests. This value will only be consulted when resolving a HandlerGuzzle
instance from the HandlerGuzzleFactory
class.
It will not affect HandlerGuzzle
objects that have been instantiated directly.
If either the username or password have been provided and are non-empty then the authentication credentials will be set.
Default is null
.
This is the authentication password that will be used for all default Guzzle requests. This value will only be consulted when resolving a HandlerGuzzle
instance from the HandlerGuzzleFactory
class.
It will not affect HandlerGuzzle
objects that have been instantiated directly.
If either the username or password have been provided and are non-empty then the authentication credentials will be set.
Default is null
.
This is the authentication method that will be used for all default Guzzle requests. This value will only be consulted when resolving a HandlerGuzzle
instance from the HandlerGuzzleFactory
class.
It will not affect HandlerGuzzle
objects that have been instantiated directly.
Allowed values are null
(HTTP Basic Authentication), digest
, and ntlm
.
Default is null
.
This is the base URI that will be used for all default Guzzle requests. This value is only consulted when resolving a HandlerGuzzle
instance from the HandlerGuzzleFactory
class.
It will not affect HandlerGuzzle
objects that have been instantiated directly.
Default is null
.
Should Guzzle return a JSON response body as an associative array when using the resolveResponseBody()
method in HandlerGuzzle
?
The default in Guzzle 5.x was to return a response body as an associative array when using the json()
response method. Guzzle 6.x does not have a json()
response method so this can be set to true in order to maintain the original functionality.
Default is false
(i.e. return the JSON response as a StdClass
instance).
Should Guzzle verify the server certificate during HTTPS requests? This typically requires the CA cert of the server's chain to be installed on the machine performing the Guzzle request.
During development, this can be set to false
safely. You may also want to set this to false
when using WAMP since WAMP tends to have issues with Guzzle when attempting to verify the server certificate.
Default is true
.