PHPackages                             gocanto/http-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. gocanto/http-client

AbandonedArchivedPhp-bundle[HTTP &amp; Networking](/categories/http)

gocanto/http-client
===================

Http client that handles retries, logging &amp; dynamic headers.

3.0.0(3y ago)14331.8k↓51.6%4MITPHPPHP ^8.0|^8.1|8.2

Since Oct 17Pushed 1y ago6 watchersCompare

[ Source](https://github.com/gocanto/http-client)[ Packagist](https://packagist.org/packages/gocanto/http-client)[ Docs](https://github.com/gocanto/http-client)[ Fund](https://github.com/sponsors/gocanto)[ GitHub Sponsors](https://github.com/gocanto)[ RSS](/packages/gocanto-http-client/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (8)Versions (7)Used By (0)

About it
--------

[](#about-it)

[![Total Downloads](https://camo.githubusercontent.com/f83817be3af9b37e62e1b6973eadc0dc821a81da6eea8c1d62315bd97dac91df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f63616e746f2f687474702d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gocanto/http-client)[![Latest Stable Version](https://camo.githubusercontent.com/d578926d87bc751c2e94dd3b2d120e5116055a8c676e6c2ab4b303ce74cbfe8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f676f63616e746f2f687474702d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gocanto/http-client)[![Build status](https://camo.githubusercontent.com/942b44f4fb75c424815d0f6f6adb9ffd42ea4d6baf9df837c28071a31cc6b328/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f676f63616e746f2f687474702d636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/gocanto/http-client)

This library is a wrapper around the famous Guzzle `HTTP` client with some goodies on top of it.

This client gives you the ability to perform `retries` and `log` any request information you may need.

Installation
------------

[](#installation)

This library uses [Composer](https://getcomposer.org) to manage its dependencies. So, before using it, make sure you have it installed in your machine. Once you have done this, you will be able to pull this library in by typing the following command in your terminal.

```
composer require gocanto/http-client

```

The reason behind
-----------------

[](#the-reason-behind)

Sometimes you will need the ability to retry a HTTP request for some given reason. This can be either due to latency issues or some timeout errors.

To avoid this interruptions, we usually perform a retry action inside a given loop. Then, we either break the loop because we have a valid response to return with or because we need to handle possible errors.

Therefore, I have created this small wrapper to handle retries actions and to log our requests/responses payload within the same action.

How does it work?
-----------------

[](#how-does-it-work)

The way how this client works is exactly the same as the one you have been used to it. You will be able to call any known guzzle method and attach the `retry` action to them.

Let's say you need to perform some HTTP request to fill seed your db with some data. To do so, you would have to write some code along these lines.

```
use GuzzleHttp\Client;

$response = (new Client)->get('http://foo.com');
```

This is a simple use case that we all have came across some other time. But, What would you do if there is an error and you need to handle some retries?

Well, if you are anything like me, you would do something like:

```
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

$retry = 1;
$response = null;

do {
    try {
        $response = (new Client)->get('http://foo.com');
    } catch (RequestException $e) {
        $retry++;
    }
} while ($response === null && $retry  We can do better!

By using the HTTP client shipped within this package, you will be able to call the retry mechanism within the same HTTP call. For Example:"

```
use Gocanto\HttpClient\HttpClient;
use GuzzleHttp\Exception\RequestException;

try {
    $response = (new HttpClient)->retry(5)->get('http://foo.com');
} catch (RequestException $e) {
    //you need to still handle errors here!
}
```

This line of code does exactly the same as the ones above, but more efficient and elegant. This library also ships a different method `onRetry()` that performs the same retries, but it also gives the ability to hook into the retry call.

You would be able to use it like so:

```
use Gocanto\HttpClient\HttpClient;
use GuzzleHttp\Exception\RequestException;

try {
    $response = (new HttpClient)->onRetry(function () {})->get('http://foo.com');
} catch (RequestException $e) {
    //you need to still handle errors here!
}
```

Here, you will be given the incoming request and response that you are handling in that particular moment. [see more](https://github.com/gocanto/http-client/blob/master/src/HttpClient.php#L82)

On-Demand Headers
-----------------

[](#on-demand-headers)

Sometimes, we need to add headers to a given `client` instance based on dynamic data.

Such as requirement is not possible on the creation stage because we do not know what information we would be dealing with. Therefore, we need a mechanism to hook into and populate this data when needed.

This `client` supports this functionality through the `with Headers` to allow on-demand headers values whenever needed.

For instance, you would be able to do something like so:

```
$client = new HttpClient;

$client->withHeaders([
      'X-GUS-1' => 'testing testing',
      'X-GUS-2' => 'testing testing',
      'X-GUS-3' => 'testing testing',
      'X-GUS-4' => 'testing testing',
])->request('GET', 'https://foo.com');
```

to populate as many headers as needed.

Contributing
------------

[](#contributing)

Please feel free to fork this package and contribute by submitting a pull request to enhance its functionality.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/gocanto/http-client/blob/master/LICENSE.md) for more information.

How can I thank you?
--------------------

[](#how-can-i-thank-you)

There are many ways you would be able to support my open source work. There is not a right one to choose, so the choice is yours.

Nevertheless 😀, I would propose the following

- ⬆️ Follow me on [Twitter](https://twitter.com/gocanto).
- ⭐ Star the repository.
- 🤝 Open a pull request to fix/improve the codebase.
- ✍️ Open a pull request to improve the documentation.
- ☕ Buy me a [coffee](https://github.com/sponsors/gocanto)?

> Thank you for reading this far. 😊

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~290 days

Total

5

Last Release

1289d ago

Major Versions

1.1.0.x-dev → 2.0.02020-11-12

2.0.0 → 3.0.02022-12-22

PHP version history (3 changes)1.0.0PHP ^7.2

2.0.0PHP ^7.4

3.0.0PHP ^8.0|^8.1|8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5246059?v=4)[Gus](/maintainers/gocanto)[@gocanto](https://github.com/gocanto)

---

Top Contributors

[![gocanto](https://avatars.githubusercontent.com/u/5246059?v=4)](https://github.com/gocanto "gocanto (60 commits)")[![emtudo](https://avatars.githubusercontent.com/u/191396?v=4)](https://github.com/emtudo "emtudo (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![hofmannsven](https://avatars.githubusercontent.com/u/1214387?v=4)](https://github.com/hofmannsven "hofmannsven (1 commits)")[![mhkb](https://avatars.githubusercontent.com/u/4683976?v=4)](https://github.com/mhkb "mhkb (1 commits)")

---

Tags

clienthttpphphttpphpclient

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/gocanto-http-client/health.svg)

```
[![Health](https://phpackages.com/badges/gocanto-http-client/health.svg)](https://phpackages.com/packages/gocanto-http-client)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

185702.8k43](/packages/laudis-neo4j-php-client)[oat-sa/tao-core

TAO core extension

66143.7k122](/packages/oat-sa-tao-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
