-
Notifications
You must be signed in to change notification settings - Fork 152
Pagination Rules and metadata
- 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
- limit: the maximum number of elements to return at once
- you MUST use limit and offset query string attributes for pagination. It's a pattern that is well understood and used in most databases
- 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
- ...
- an "items" array containing the corresponding results
- 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 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).
See concurrency section: Concurrency-vs-Pagination
See sorting section: Sorting-Metadata and the corresponding example: Sorting-Example
Check out the following page: Error-handling-Warnings
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.
You MAY add support for a "excludeMetadata" URI parameter if you want your API clients to be able to exclude the metadata.
Check out the Pagination-Example page for a representative example.
This project is distributed under the terms of the EUPL FOSS license
REST Resources Design Workflow
REST Resources Single items and collections
REST Resources Many to many Relations
REST Resources Relations expansion
HTTP Status Codes Success (2xx)
HTTP Status Codes Redirection (3xx)
HTTP Status Codes Client Error (4xx)
HTTP Status Codes Server Error (5xx)
Pagination Out of range/bounds
Long-running Operations Example
Concurrency vs Delete operation
Caching and conditional requests About
Caching and conditional requests Rules
Caching and conditional requests HTTP headers
Error handling Example with a single error
Error handling Example with multiple errors
Error handling Example with parameters
Error handling Example with additional metadata
Bulk operations HTTP status codes
Bulk operations Resources naming convention
Bulk operations Creation example
Bulk operations Update example
Bulk operations Create and update example
File upload Simple file upload
File upload Simple file upload example
File upload Complex file upload
File upload Complex file upload example
REST Security General recommendations
REST Security Insecure direct object references