Skip to content

Pagination

Every index answers with the same envelope: the records under data, the paging under paging.

{
"data": [ … ],
"paging": { "total": 42, "page": 1, "pages": 3, "next": "https://you.mudda.today/cards.json?page=2" }
}

next is the URL of the following page, built from the request’s own host, or null on the last page or past it. Follow it rather than building page numbers yourself. A walk that stops at a null next ends, as long as the records aren’t growing faster than it reads them; cap the pages anyway, and stop on any failed request.

There is no per_page, because the page size isn’t fixed: pages ramp 15, 30, 50, then 100 records and stay at 100. Read total and pages, not a page size. The X-Total-Count and Link: <…?page=2>; rel="next" headers carry the same information.

Terminal window
set -euo pipefail
url="$MUDDA/cards.json"
for _ in $(seq 1 1000); do
page=$(curl -fsS -H "Authorization: Bearer $TOKEN" "$url")
echo "$page" | jq -e '.data and .paging' > /dev/null # stop on anything but an index page
echo "$page" | jq -c '.data[] | {number, title}'
url=$(echo "$page" | jq -r '.paging.next // empty')
[ -n "$url" ] || break
done