duncan3dc / guzzle-tools
A few tools for working with Guzzle
Requires
- php: ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^8.0
- guzzlehttp/psr7: ^3.0
- psr/http-message: ^1.0 || ^2.0
- psr/log: ^1.0.2 || ^2.0 || ^3.0
Requires (Dev)
- duncan3dc/object-intruder: ^1.0
- infection/infection: ^0.26.19
- maglnet/composer-require-checker: ^4.0
- mockery/mockery: ^1.4.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-mockery: ^2.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^4.0
This package is auto-updated.
Last update: 2026-07-30 12:20:04 UTC
README
A PHP library offering some add-ons for Guzzle.
Installation
The recommended method of installing this library is via Composer.
Run the following command from your project root:
$ composer require duncan3dc/guzzle-tools
Quick Examples
Logging
When working with Guzzle I got bored of searching for the solution to output the request/response every time I wanted a quick debug, this library makes it easy:
$client = \duncan3dc\Guzzle\Factory::getClient(); $client->request("GET", "http://example.com/");
Running the above would output this on the command line:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GET / HTTP/1.1
User-Agent: GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.1.0RC3
Host: example.com
--------------------------------------------------------------------------------
HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html
Date: Mon, 09 Jan 2017 14:42:17 GMT
Etag: "359670651+gzip+ident"
Expires: Mon, 16 Jan 2017 14:42:17 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (ewr/15BD)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270
<!doctype html>
<html>
<head>
<title>Example Domain</title>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Request Building
As of version 6.0.0 Guzzle no longer offers a way to build a request instance to send later, this library provides a simple workaround:
$request = \duncan3dc\Guzzle\Request::make("GET", "https://example.com/", [ "query" => [ "date" => date("Y-m-d"), ], ]); # There's also an alias on the main factory class $request = \duncan3dc\Guzzle\Factory::request("GET", "https://example.com/");
Simple Requests
When all you need is a basic GET/POST, you can use the Http class:
$response = \duncan3dc\Guzzle\Http::get("https://example.com/", [ "date" => date("Y-m-d"), ]); $response = \duncan3dc\Guzzle\Http::post("https://example.com/", [ "date" => date("Y-m-d"), ]);
Changelog
A Changelog has been available since the beginning of time
Where to get help
Found a bug? Got a question? Just not sure how something works?
Please create an issue and I'll do my best to help out.
Alternatively you can connect with me on LinkedIn