cacahouwete / lazy-api-collection
Handle rest api endpoint with pagination through an unique iterable
Installs: 2 183
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- symfony/framework-bundle: ^5.4 | ^6
- symfony/http-client: ^5.4 | ^6
- symfony/serializer: ^5.4 | ^6
- symfony/thanks: ^1
Suggests
- symfony/framework-bundle: ^5.4 | ^6
- symfony/http-client: ^5.4 | ^6
- symfony/serializer: ^5.4 | ^6
README
PHP tool to have an easy way to iterate an api with multiple pages
Installation with symfony
composer require cacahouwete/lazy-api-collection
Add bundle in your symfony project
<?php // config/bundles.php return [ ... LazyApiCollection\Bridge\Symfony\LazyApiCollectionBundle::class => ['all' => true], ]
Basic usage with symfony
<?php namespace App\ApiEntity; // src/ApiEntity/Dummy.php final class Dummy { public string $field1; public string $field2; .... }
// src/ApiRepository/DummyApiRepository.php namespace App\ApiRepository; use LazyApiCollection\Bridge\Symfony\Builder\LazyApiCollectionBuilderInterface; use LazyApiCollection\Model\ApiCollection; use LazyApiCollection\Model\LazyApiCollection; final class DummyApiRepository { private const PATH = '/api/dummies'; private LazyApiCollectionBuilderInterface $lazyApiCollectionBuilder; private string $targetUrl; public function __construct(LazyApiCollectionBuilderInterface $lazyApiCollectionBuilder, string $targetUrl) { $this->lazyApiCollectionBuilder = $lazyApiCollectionBuilder; $this->targetUrl = $targetUrl; } /** * @return iterable<Dummy> */ public function findAllByPageAndNbItem(): iterable { return $this->lazyApiCollectionBuilder ->create($this->targetUrl.self::PATH, Dummy::class) ->build() ; } }