Server side
Server side pagination is controlled with pagination_ setting (enabled by default). When it is enabled every collection GET response contains at most pagination_ items and the client chooses the page with page query param (name can be changed with page_).
To disable pagination for a resource (e.g. small dictionaries which should always be returned in full) set pagination_ to false:
use SourceBroker\T3api\Annotation as T3api;
/**
* @T3api\ApiResource(
* collectionOperations={
* "get"={
* "path"="/news/tags",
* },
* },
* attributes={
* "pagination_enabled"=false,
* }
* )
*/
class Tag extends \GeorgRinger\News\Domain\Model\Tag
{
}
To change the name of the page param or the number of items on page:
/**
* @T3api\ApiResource(
* ...
* attributes={
* "pagination_items_per_page"=12,
* "page_parameter_name"="p",
* }
* )
*/
Now the third page is available under ?p=3.
Note
Requesting a page beyond the last one returns an empty hydra: list (still with correct hydra:), not an error.
An empty collection has one page (hydra: and hydra: point to page 1).
The page number has to be an integer greater than or equal to 1. Any other value (?page=0, ?page=-, ?page=abc) results in 400 Bad Request:
{
"hydra:title": "Invalid pagination parameter",
"hydra:description": "Parameter `page` has to be an integer greater than or equal to 1",
"hydra:code": 1791043200
}
Real examples. Run "ddev restart && ddev ci 14" and try those links below.
- Get first page of news (news resource returns 20 items per page):
- Get page which does not exist -
hydra:is empty:member