Issue
In API Platform there exist two different settings where to me it is not clear what the difference is betweem them. This is pagination_items_per_page
and pagination_maximum_items_per_page
. In the pagination documentation it is extensively explained how you can configure these settings, but not when you should use it.
The default (global) configuration is as follows, as seen in the configuration documentation.
api_platform:
defaults:
# The default number of items per page.
pagination_items_per_page: 30
# The maximum number of items per page.
pagination_maximum_items_per_page: ~
I have also followed this Symfony Casts about the topic of API Platform pagination, and there only the setting of pagination_items_per_page
is used. This is suggesting that this setting is probably what you need in most cases.
When you set the pagination_items_per_page
, does that not already set how many items will be returned anyways. When do you use pagination_maximum_items_per_page
?
Solution
Since there is a setting to allow consumers of the API to change the amount of results via a query parameter, the pagination_maximum_items_per_page
makes sense to make sure the user does not enter such a large value that your result is too large for your resources.
To allow pagination to be used as a query parameter globally, use the following configuration:
api_platform:
defaults:
pagination_client_enabled: true
pagination_client_items_per_page: true
I still have the open question whether this is the only situation where you would use the pagination_maximum_items_per_page
, or if this setting also prevents a very large pagination setting for a specific resource (with: @ApiResource(attributes={"pagination_items_per_page"=9999})
for example) by overwriting that value if it exceeds the max per page setting.
Answered By - Robin Bastiaan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.