Skip to content

Pagination Rules and metadata

Sebastien Dubois edited this page Jan 25, 2018 · 11 revisions

Rules

  • requests for collections MUST always be paginated
  • API clients MUST be able to clearly specify the slice of the data set they want to retrieve.
    • you MUST use limit and offset query string attributes for pagination. It's a pattern that is well understood and used in most databases
      • limit: the maximum number of elements to return at once
        • MUST be > 0
        • MUST NOT be > 1000
      • offset: where to start
        • MUST NOT be < 0
      • offset and limit MUST both be specified by API clients. If either is missing, default values are applied
        • limit: 10 (also set to this if 0 is passed)
        • offset: 0
  • a paginated response MUST contain
    • an "items" array containing the corresponding results
      • respecting the rules defined in the filtering section
    • a "metadata" object containing information about
      • the pagination values
      • the sorting parameters
      • the ETag values for all the given items
      • ...

Metadata

Pagination metadata

  • pagination: an object containing all the pagination metadata:
  • limit: the requested limit (provided by the client)
  • offset: the requested offset (provided by the client)
  • previousOffset: the previous offset or null if there is none
  • nextOffset: the next offset or null if there is none
  • currentPage: the current page or null if it does not exist (e.g., out of bounds)
    • if the offset falls between two pages, then the currentPage number should be the one of the page that the first item of the resultset is part of
  • pageCount: the total number of pages
  • totalCount: the total number of elements in the collection

Pagination metadata defaults

Pagination defaults vary depending on the size of the data.

You SHOULD use limit=10 and offset=0 as defaults. These defaults SHOULD apply even if limit/offset are not specified explicitly in the request.

If each item is very large, then you MAY set the limit lower. On the opposite, if objects are very small, a larger limit could make sense (i.e., less requests = potentially increased performance perceived).

Metadata for concurrency control

See concurrency section: Concurrency-vs-Pagination

Metadata for sorting

See sorting section: Sorting-Metadata and the corresponding example: Sorting-Example

Metadata for warnings

Check out the following page: Error-handling-Warnings

Custom metadata

In addition to all the above, you MAY also introduce custom metadata as you see fit. If you do so, for client implementation simplicity, you SHOULD add it inside a "custom" object within the "metadata" object.

Omitting metadata

You MAY add support for a "excludeMetadata" URI parameter if you want your API clients to be able to exclude the metadata.

Example

Check out the Pagination-Example page for a representative example.

History

REST

REST

REST API Design Goals

REST Constraints

REST Resources

REST Resources Design Workflow

REST Resources Naming

REST Resources URIs

REST Resources Parameters

REST Resources Single items and collections

REST Resources Relations

REST Resources Many to many Relations

REST Resources Relations expansion

REST Resources Actions

REST API Versioning

REST API Documentation

HTTP

HTTP Methods

HTTP Status Codes

HTTP Status Codes Success (2xx)

HTTP Status Codes Redirection (3xx)

HTTP Status Codes Client Error (4xx)

HTTP Status Codes Server Error (5xx)

Media types

CRUD Operations

CRUD About

CRUD Create Single item

CRUD Retrieve Single item

CRUD Retrieve Collection

CRUD Update Single item

CRUD Delete Single item

Pagination

Pagination About

Pagination Rules and metadata

Pagination Example

Pagination Out of range/bounds

Filtering

Filtering About

Filtering Using styles

Filtering Using includes

Filtering Using excludes

Sorting

Sorting About

Sorting Metadata

Sorting Example

Searching

Searching About

Searching Local search

Searching Scoped search

Searching Global search

Searching Advanced search

Searching Wildcards

Searching Formatting

Long-running operations

Long-running Operations About

Long-running Operations Flow

Long-running Operations Rules

Long-running Operations Example

Concurrency control

Concurrency About

Concurrency Headers to use

Concurrency vs Delete operation

Concurrency vs Pagination

Caching and conditional requests

Caching and conditional requests About

Caching and conditional requests Rules

Caching and conditional requests HTTP headers

Conditional requests

Cache control

Error handling

Error handling About

Error handling Expectations

Error handling Status codes

Error handling Error details

Error handling Example with a single error

Error handling Example with multiple errors

Error handling Example with parameters

Error handling Example with additional metadata

Error handling Warnings

Compression

Compression About

Bulk operations

Bulk operations About

Bulk operations Types

Bulk operations Atomic

Bulk operations Non-atomic

Bulk operations Asynchronous

Bulk operations HTTP status codes

Bulk operations Resources naming convention

Bulk operations Errors

Bulk operations Creation example

Bulk operations Update example

Bulk operations Create and update example

File upload

File upload About

File upload File sizes

File upload Simple file upload

File upload Simple file upload example

File upload Complex file upload

File upload Complex file upload example

Security recommendations

REST Security General recommendations

REST Security Transport layer

REST Security Error handling

REST Security Insecure direct object references

REST Security CORS

REST Security Updates and consistency

REST Security API keys

Miscellaneous

Data formats

Internationalization

Rate limiting

Null values

Dates and times

Redirections

References

Clone this wiki locally