Modules@robinpath/pagination
pagination

@robinpath/pagination

0.1.2Node.jsPublic

Auto-paginate APIs: cursor, offset, and link-header strategies

Pagination

Auto-paginate APIs with offset, cursor, page-number, and Link-header strategies

Package: @robinpath/pagination | Category: Other | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the pagination module when you need to:

  • Auto-paginate an API and collect all items -- Use pagination.fetchAll to perform this operation
  • Fetch a single page of results -- Use pagination.fetchPage to perform this operation
  • Parse a Link header into rel-url pairs -- Use pagination.parseLinkHeader to perform this operation
  • Build a paginated URL with page/limit parameters -- Use pagination.buildPageUrl to perform this operation

Quick Reference

FunctionDescriptionReturns
fetchAllAuto-paginate an API and collect all items{items, total}
fetchPageFetch a single page of results{items, page, pageSize, hasMore, total}
parseLinkHeaderParse a Link header into rel-url pairs{next, prev, first, last} URLs
buildPageUrlBuild a paginated URL with page/limit parametersComplete URL with pagination params

Functions

fetchAll

Auto-paginate an API and collect all items

Module: pagination | Returns: object -- {items, total}

pagination.fetchAll "https://api.example.com/users" {"strategy": "offset", "pageSize": 100}
ParameterTypeRequiredDescription
urlstringYesAPI base URL
optionsobjectYes{strategy: offset

fetchPage

Fetch a single page of results

Module: pagination | Returns: object -- {items, page, pageSize, hasMore, total}

pagination.fetchPage "https://api.example.com/users" 2 {"pageSize": 20}
ParameterTypeRequiredDescription
urlstringYesAPI URL
pagenumberYesPage number
optionsobjectNo{pageSize, headers, itemsKey}

parseLinkHeader

Parse a Link header into rel-url pairs

Module: pagination | Returns: object -- {next, prev, first, last} URLs

pagination.parseLinkHeader $linkHeader
ParameterTypeRequiredDescription
headerstringYesLink header value

buildPageUrl

Build a paginated URL with page/limit parameters

Module: pagination | Returns: string -- Complete URL with pagination params

pagination.buildPageUrl "https://api.example.com/users" 3 {"limit": 50}
ParameterTypeRequiredDescription
baseUrlstringYesBase URL
pagenumberYesPage number
optionsobjectNo{limit, pageParam, limitParam}

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Fetch all and validate result"
do
  set $result as pagination.fetchAll "https://api.example.com/users" {"strategy": "offset", "pageSize": 100}
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Pagination workflow

Chain multiple pagination operations together.

@desc "Fetch all, fetch page, and more"
do
  set $r_fetchAll as pagination.fetchAll "https://api.example.com/users" {"strategy": "offset", "pageSize": 100}
  set $r_fetchPage as pagination.fetchPage "https://api.example.com/users" 2 {"pageSize": 20}
  set $r_parseLinkHeader as pagination.parseLinkHeader $linkHeader
  print "All operations complete"
enddo

2. Safe fetchAll with validation

Check results before proceeding.

@desc "Fetch all and validate result"
do
  set $result as pagination.fetchAll "https://api.example.com/users" {"strategy": "offset", "pageSize": 100}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/pagination

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size4.2 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities