Client side
By default client can only choose the page number. Two more options can be opened to the client per resource (or globally):
pagination_- client can enable or disable pagination by sendingclient_ enabled ?pagination=1or?pagination=0(param name can be changed withenabled_). If the param is not sent,parameter_ name pagination_setting decides.enabled pagination_- client can change number of items per page by sendingclient_ items_ per_ page ?items(param name can be changed withPer Page=<int> items_).per_ page_ parameter_ name
use SourceBroker\T3api\Annotation as T3api;
/**
* @T3api\ApiResource(
* collectionOperations={
* "get"={
* "path"="/news/news",
* },
* },
* attributes={
* "pagination_client_enabled"=true,
* "pagination_client_items_per_page"=true,
* "maximum_items_per_page"=100,
* }
* )
*/
class News extends \GeorgRinger\News\Domain\Model\News
{
}
Important
Always set maximum_ when you enable pagination_. Number of items requested by the client is never higher than maximum_, so ?items returns 100 items with configuration above. Keep in mind that pagination_ allows the client to fetch the whole collection with ?pagination=0 regardless of maximum_.
Number of items per page has to be an integer greater than or equal to 0, otherwise 400 Bad Request is returned. ?items returns no items, only hydra: - useful when the client needs only the number of all items. It can not be combined with a page greater than 1.
Real examples. Run "ddev restart && ddev ci 14" and try those links below.
- Get 4 news, sorted by title, from page 3 or 6 only - filters, sorting and pagination can be combined:
- Get only the number of all news (
hydra:is empty):member
- Disable pagination -
hydra:is empty and all news are returned:view