Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can a client follow pagination links in an API response?

Quick answer

Check the API documentation for where pagination links appear. If the response includes a documented next link—such as a Link header relation marked rel="next" or a JSON field—request the returned link as the API instructs, then check the new response the same way. Stop when the documented instructions indicate there are no more pages. Don’t guess parameter names; pagination formats vary by API. [S1] [S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I receive one page of results from an API. How do I know where the next page is?

Geez

Start with that API’s pagination documentation, then inspect the response in the location it describes. One HTTP option is a Link response header containing related links; for pagination, a link may be marked with rel="next". A JSON response may use a field such as nextLink. These are examples, not universal rules: the format depends on the API. [S1] [S2]

For example, a hypothetical response might include:

Link: <[next-page-link]>; rel="next"

[next-page-link] is a placeholder for the value actually returned by the API. Use the documented link format rather than assuming that adding page=2 or another parameter will work.

Follow-up question

If the response gives me a next link, should I build a new request from its parameters?

Geez

Follow the returned link according to the API’s documented instructions instead of rebuilding it from guessed parameters. The continuation format is specific to the API. For example, Microsoft Data API builder documents a product-specific pattern in which a paginated JSON response can contain nextLink and the continuation request uses the returned $after token. That example does not establish a rule for other APIs. [S2]

A practical sequence is:

  1. Locate the documented next-link field or header in the response.
  2. If a link is provided, use it as directed by the API documentation.
  3. Read the new response and check for its next link in the same documented way.

Don’t substitute a guessed token or parameter for the returned value.

Follow-up question

What should my client do when there is no next link, or the response format is unclear?

Geez

Check the API’s documentation to learn what the absence of a link means and how the response is structured. If the documentation says that no next link means there are no further pages, stop. If it doesn’t explain the response, don’t infer the reason or generate another request from an assumed page number; clarify the documented pagination behavior first.

You can express the basic control flow as pseudocode:

response = first_response
process(response)
link = documented_next_link(response)

while link is present:
    response = request(link)
    process(response)
    link = documented_next_link(response)

This is illustrative, not ready-to-run code: the link lookup and request handling depend on the API and your client.

Follow-up question

Can you show a compact example of applying that approach without assuming a specific API?

Geez

Suppose the API documentation says to find the next page in a Link header relation named next. If a response contains Link: <[next-page-link]>; rel="next", the client reads that documented relation and requests the returned link. It then checks the new response for the same relation. If the documentation defines what to do when the relation is absent, follow that instruction. If the API instead documents a JSON nextLink field, use that field and its documented rules rather than looking for the header.

The HTTP Link header can carry links to related resources, including pagination links, but that does not establish which format a particular API uses. Likewise, Microsoft Data API builder’s nextLink and $after example describes that product’s scheme, not a universal convention. [S1] [S2]

A practical checklist

  • Find the API’s documented pagination format and where the next link appears.

  • Inspect the response for the documented link or relation.

  • Use the returned link according to the API’s instructions; don’t guess parameter names.

  • Check each new response for the next link in the documented location.

  • Follow the documentation on when to stop or what to do if the format is unclear.

A few more useful answers

Does every paginated API use a Link header?

No. A Link header with rel="next" is one possible format. An API may document a JSON field or another scheme, so check the documentation for the API you are calling. [S1]

Can I assume a field named `nextLink` uses `$after`?

No. The documented nextLink and $after pattern applies to Microsoft Data API builder’s described pagination scheme, not APIs generally. Follow the instructions for the API you are calling. [S2]

What does the absence of a next link prove?

By itself, it does not establish why the link is absent. Check the API’s documentation for what that response means and whether another page should be requested.

Sources

References used for this guide.

  1. [S1] Link header — MDN Web Docs
    developer.mozilla.org · Checked
  2. [S2] How to call REST endpoints — Data API builder
    learn.microsoft.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work