liveBook · Manning

Cursor

As explained in API Design Patterns

A cursor is a position marker that identifies the point from which the next portion of paged data should be retrieved.

A cursor is an opaque position marker that lets an API retrieve the next chunk of paged data. The server returns results with the next token, allowing consumers to continue until the token is empty. section 21.2 section 21.3.2

Use cursor responses carefully:

  • Do not treat a partially full page as the end; page sizes are maximums, not exact sizes. section 21.3.2
  • Continue when results are empty but the next token is nonempty; the server may have stopped searching at a time limit. section 21.3.2
  • Keep token contents opaque; they can encode whatever state the server needs, such as serialized state or a limit and offset. section 21.3.2

Paging through a large attachment

A read request can carry an attachment ID, pageToken, and maxBytes. Each response returns a chunk, a field mask identifying the supplied fields, and nextPageToken. The consumer appends chunks and stops when the token is empty. section 21.3.4

Figure 21.1 Flow of pagination

Follow the request-and-response flow from the first page through subsequent cursor-based requests. section 21.2

How API Design Patterns covers it

How deep it goes
Defines termination, opacity, empty-page behavior, and large-resource continuation, without specifying one token representation.
Examples
Uses multi-page resource retrieval, empty-result responses, and chunked attachment reads.
What you can do after
Operate pagination by passing returned tokens and stopping only when the next token is empty.
How it connects
Connects pagination with page tokens, maximum page sizes, field masks, and strong consistency.

Also explained in

Compare how 7 books explain cursor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.