Pagination
Content
Overview
ULM includes a variety of APIs that can return multiple results. For instance, GET user/{userId}/features returns all features associated to the given user ID. Since ULM's data model supports many-to-many associations between entities, any one entity can grow to have a significantly large number of associations.
A high number of results within a single response can put a strain on the system or the UI retrieving and rendering those entities. To control the number of results in a given call, a select number of ULM APIs support pagination to break up large results into easily renderable pages.
Pagination Parameters
The optional size and offset request parameters enable the fetching of data in smaller, manageable segments:
Name | Type | Required | Description | Default Size | Notes |
---|---|---|---|---|---|
size | request parameters (num) | No | Indicates the maximum number of entities to be included in a single-page response. Maximum size is 100. | 20 | Maximum size is 100. Cannot be a negative value. |
offset | request parameter (num) | No | Indicates the number of results to skip in a response. For example, an offset of 20 means that the response skips the first 20 results (and thus starts at 21). | 0 | Cannot be a negative value. |
A request that exceeds the max size or has a negative offset value results in a HTTP 400 (BAD REQUEST).
Note: Server-side application settings control the size parameter's default and maximum rules:
- system.rest.defaultPageSize controls the size parameter's default value.
- system.rest.maxPageSize controls the size parameter's highest maximum value.
Pagination Header
Successful responses include an X-Total-Count header that indicates the total number of available entities.
Name | Type | Description |
---|---|---|
X-Total-Count | response header | Any successful request (OK 200) must respond with the response header "X-Total-Count" set to the available number of entities |
Examples
Multiple Page Response
Here is a simple pagination where there is a total count of 4 results broken up into two pages.
Page 1 - GET Request |
---|
GET /membership/1/subscriptions?offset=0&size=2
|
Page 1 - GET Response |
---|
Header: X-Total-Count = 4
[
{
"id": 1,
"displayName": "Cable TV"
},
{
"id": 2,
"displayName": "Video on Demand"
}
]
|
Page 2 - GET Request |
---|
GET /membership/1/subscriptions?offest=2&size=2
|
Page 2 - GET Response |
---|
Header: X-Total-Count = 4
[
{
"id": 3,
"displayName": "HBO"
},
{
"id": 4,
"displayName": "NetFlix"
}
]
|
Sending a Request With Zero Size Value
A request size of zero will retrieve all results if the total number of results is less than the max page size.
For example, assume that there are 3 available results, and that system.rest.maxPageSize=5.
GET Request |
---|
GET /membership/1/subscriptions?size=0
|
GET Response |
---|
Header: X-Total-Count = 3
[
{
"id": 101,
"displayName": "Gaming Streaming Service"
},
{
"id": 2,
"displayName": "Music Streaming Service"
},
{
"id": 3,
"displayName": "Movie Streaming Service"
}
]
|
A request size of zero returns an error response if the total number of results exceeds max page size.
For example, assume that there are 10 available results, and that system.rest.maxPageSize=5.
GET Response |
---|
"operationError": {
"code": "max-return-page-size",
"message": "Total number of results exceeds the maximum page size"
}
|
Page Size Bigger Than Maximum Allowed
A request with a size value that exceeds the maximum page size returns an error response.
For example, in the call below, assume that system.rest.maxPageSize=10.
GET Request |
---|
GET /membership/1/subscriptions?offset=0&size=20
|
GET Response |
---|
{
"operationError": {
"code": "page-size-error",
"message": "Requested page size is bigger than allowed maximum size"
}
}
|
API Listing
The following table contains GET calls that support pagination parameters, and that return a X-Total-Count header.
GET Calls That Support Pagination Parameters | ||
---|---|---|
/user/runtimes | /user/{userId}/runtimes | /user/features |
/user/{userId}features | /user/subscriptions | /user/{userId}/subscriptions |
/user/groups | /user/{userId}/groups | /user/accounts |
/user/{userId}/accounts | /group/{groupId}/users | /group/{groupId}/accounts |
/group/{groupId}/subscriptions | /group/{groupId}/runtimes | /group/{groupId}/features |
/account/{accountId}/users | /account/{accountId}/groups | /account/{accountId}/runtimes |
/account/{accountId}/subscriptions | /subscription/{subscriptionId}/users | /subscription/{subscriptionId}/groups |
/subscription/{subscriptionId}/features | /subscription/{subscriptionId}/runtimes | /feature/{featureId}/groups |
/feature/{featureId}/runtimes | /feature/{featureId}/users | /runtime/{runtimeId}/groups |
/runtime/{runtimeId}/accounts | /runtime/{runtimeId}/subscriptions | /runtime/{runtimeId}/features |