PHPackages                             husail/http-iterator - 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. husail/http-iterator

ActiveLibrary[HTTP &amp; Networking](/categories/http)

husail/http-iterator
====================

Http Iterator

v1.1.0(1y ago)02.5k↑11.1%MITPHPPHP ^8.1

Since May 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/husail/http-iterator)[ Packagist](https://packagist.org/packages/husail/http-iterator)[ Docs](https://github.com/husail/http-iterator)[ RSS](/packages/husail-http-iterator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

HttpIterator
============

[](#httpiterator)

The `HttpIterator` package provides a PHP iterator that simplifies the processing of large volumes of paginated data from HTTP requests. It's particularly useful for APIs with page-based results, supporting retries in case of transient failures.

---

📦 Installation
--------------

[](#-installation)

```
composer require husail/http-iterator
```

---

🔧 Usage Example
---------------

[](#-usage-example)

### Basic Usage

[](#basic-usage)

```
use Husail\HttpIterator\HttpIterator;
use Illuminate\Support\Facades\Http;

$perPage = 10;
$startPage = 1;
HttpIterator::run($perPage, $startPage, function ($iterator) {
     $response = Http::get('https://example.com/api/transactions', [
        'page' => $iterator->currentPage(),
        'per_page' => $iterator->perPage(),
    ]);

    if (!$iterator->hasInitialized()) {
        $iterator->setTotalResult($response->json('total_elements'));
    }

    TransactionRepository::sync($response->json('data'))
    //...

    $iterator->nextPage();
});
```

### Handling Retries

[](#handling-retries)

You can use the `retry()` method to explicitly repeat the current iteration without advancing to the next page. This is useful for handling transient errors such as API throttling (HTTP 429) or temporary network issues. Retries are limited by the `maxRetries` parameter (default: `3`).
After reaching this limit, the iterator will automatically stop, unless the retry counter is reset by a successful interaction (e.g., calling `nextPage()`, `toPage()`, or `lastPage()`), or by a manual call to `resetRetries()`.

```
use Husail\HttpIterator\HttpIterator;
use Illuminate\Support\Facades\Http;

const THROTTLE_DELAY_SECONDS = 60;

$perPage = 10;
$startPage = 1;
HttpIterator::run($perPage, $startPage, function ($iterator) {
     $response = Http::get('https://example.com/api/transactions', [
        'page' => $iterator->currentPage(),
        'per_page' => $iterator->perPage(),
    ]);

    if ($response->status() === 429) {
        sleep(THROTTLE_DELAY_SECONDS);
        $iterator->retry();
    }

    if (!$iterator->hasInitialized()) {
        $iterator->setTotalResult($response->json('total_elements'));
    }

    TransactionRepository::sync($response->json('data'))
    //...

    $iterator->nextPage();
});
```

---

🧰 API Reference
---------------

[](#-api-reference)

- `HttpIterator::run(int $perPage, int $currentPage, callable $callableRun, ?callable $callableException = null, int $maxRetries = 3)`: Execute the iterator with the provided callables.
- `nextPage()`: Move to the next page and reset retry count.
- `lastPage()`: Jump to the last page.
- `toPage(int $page)`: Jump to a specific page.
- `setPerPage(int $length)`: Set the page size.
- `setTotalResult(int $length)`: Set the total number of results.
- `currentPage()`: Get the current page number.
- `perPage()`: Get the per-page count.
- `totalResult()`: Get the total number of results.
- `totalPages()`: Get the total number of pages.
- `finish()`: Mark the iteration as finished.
- `hasInitialized()`: Returns whether total result count has been set.
- `hasFinished()`: Returns whether the iteration was manually finished.
- `hasNextPage()`: Returns whether more pages are available.
- `retry()`: Retry the current iteration (increments retry count and throws).

---

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Feel free to submit issues or pull requests to help improve the package.

---

📜 License
---------

[](#-license)

This package is open-source software licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance48

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~176 days

Total

3

Last Release

379d ago

PHP version history (2 changes)v1.0.0PHP ^7.4|^8.0

v1.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d639b59331f31fc8422a8172c75d8b7ff59c37dd60a16035c1a468aacb9b1823?d=identicon)[victordanilo](/maintainers/victordanilo)

---

Top Contributors

[![victordanilo](https://avatars.githubusercontent.com/u/4293184?v=4)](https://github.com/victordanilo "victordanilo (20 commits)")

---

Tags

iteratorhttp-iterator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/husail-http-iterator/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48247.0M384](/packages/php-http-curl-client)

PHPackages © 2026

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