Pagination
The SDK provides two approaches to pagination: manual control via list() and automatic iteration via list_all().
Manual Pagination
All list() methods accept skip and take parameters for manual pagination. The response includes a meta->{count}
field with the total number of matching records.
Parameters
- Name
skip- Type
- integer
- Description
Number of records to skip. Defaults to
0.
- Name
take- Type
- integer
- Description
Number of records to return. Defaults to
25.
Response Meta
- Name
meta->{count}- Type
- integer
- Description
Total number of records matching the query. Use this with
skipandtaketo calculate pages.
Manual Pagination
# Fetch page 1 (first 20 records)
my $page1 = $client->bookings->list(
organisation => 'org-id',
skip => 0,
take => 20,
);
print scalar @{ $page1->{data} }; # Items on this page
print $page1->{meta}{count}; # Total count, e.g. 154
# Fetch page 2
my $page2 = $client->bookings->list(
organisation => 'org-id',
skip => 20,
take => 20,
);
Auto-Pagination
Most resources provide a list_all() method that returns a Felloh::Paginator object. This automatically fetches pages
as you iterate, so you never have to manage skip and take manually.
The paginator fetches 25 records per page internally.
You can iterate using the each() method with a callback, which processes items one at a time without loading everything into memory.
Auto-Pagination with each()
# Iterate one by one
$client->bookings->list_all(
organisation => 'org-id',
)->each(sub {
my ($booking) = @_;
print "$booking->{id} $booking->{customer_name}\n";
});
Collecting All Results
If you need all records in memory at once, use the all() method on the paginator to collect all items into an array ref.
- Name
all()- Type
- method
- Description
Returns an array ref containing all items from every page.
Collecting All Results
use Felloh::Client;
my $client = Felloh::Client->new(
public_key => 'your-public-key',
private_key => 'your-private-key',
);
my $all_bookings = $client->bookings->list_all(
organisation => 'org-id',
)->all();
print "Total: " . scalar(@$all_bookings) . " bookings\n";
