Pagination
Collection GET operations are paginated by default. Number of items on a page, possibility to change it by the client and possibility to disable pagination by the client are configurable globally and per resource.
Pagination data is returned in hydra: of collection response, e.g. for /_:
{
"hydra:member": [ ... ],
"hydra:totalItems": 6,
"hydra:view": {
"hydra:first": "/_api/news/news?itemsPerPage=2&page=1",
"hydra:last": "/_api/news/news?itemsPerPage=2&page=3",
"hydra:prev": "/_api/news/news?itemsPerPage=2&page=1",
"hydra:next": "/_api/news/news?itemsPerPage=2&page=3",
"hydra:pages": [
"/_api/news/news?itemsPerPage=2&page=1",
"/_api/news/news?itemsPerPage=2&page=2",
"/_api/news/news?itemsPerPage=2&page=3"
],
"hydra:page": 2
},
"hydra:search": { ... }
}
hydra: is skipped on the first page and hydra: is skipped on the last page. All other query params (e.g. filters) are kept in the generated links. hydra: is empty if pagination is disabled.
Available settings
| Setting | Default | Description |
|---|---|---|
pagination_ | true | Enables pagination on the server side. See Server side. |
pagination_ | 30 | Number of items returned on a single page. |
maximum_ | 9999999 | Upper limit of items on a single page. Applies also to the number requested by the client. |
page_ | page | Name of the query param holding the number of the requested page. |
pagination_ | false | Allows client to enable / disable pagination with query param. See Client side. |
enabled_ | pagination | Name of the query param used by the client to enable / disable pagination. |
pagination_ | false | Allows client to change number of items per page with query param. |
items_ | items | Name of the query param used by the client to change number of items per page. |
Global configuration
Default values are kept in $GLOBALS. They can be changed e.g. in ext_ of your extension:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['pagination'] = array_merge(
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['pagination'],
[
'pagination_items_per_page' => 10,
'maximum_items_per_page' => 100,
]
);
Resource specific configuration
Each of the settings can be overridden for a single resource in attributes of Api annotation. Example below is the configuration used by news resource in testing instance:
use SourceBroker\T3api\Annotation as T3api;
/**
* @T3api\ApiResource(
* collectionOperations={
* "get"={
* "path"="/news/news",
* },
* },
* attributes={
* "pagination_client_enabled"=true,
* "pagination_items_per_page"=20,
* "maximum_items_per_page"=100,
* "pagination_client_items_per_page"=true,
* }
* )
*/
class News extends \GeorgRinger\News\Domain\Model\News
{
}
Real examples. Run "ddev restart && ddev ci 14" and try those links below.
- Get second page of news with 2 items per page: