Answer the question
In order to leave comments, you need to log in
How to select all values at once in yii2 restful in server response without pagination?
In general, I am currently making a mobile application. Under it, a backend was made on yii2 rest api.
The response from the server to the /games request comes with approximately the following values:
[{"championship":"Indian I-League","homeTeam":"Mumbai City","awayTeam":"SC Goa"},
{"championship":"Gulf Cup of Nations","homeTeam":"UAE","awayTeam":"Kuwait"}
...]
...
Server →Apache/2.4.7 (Ubuntu)
X-Pagination-Current-Page →1
X-Pagination-Page-Count →7
X-Pagination-Per-Page →20
X-Pagination-Total-Count →121
X-Powered-By →PHP/5.5.9-1ubuntu4.5
Answer the question
In order to leave comments, you need to log in
You can set the page size:
When /games is requested, yii\rest\IndexAction is executed , which returns ActiveDataProvider(['query' => $modelClass::find(),]) . Those. the Pagination object is default there ($pageParam = 'page', $pageSizeParam = 'per-page', $pageSizeLimit = [1, 50]). And the default yii\data\Pagination tries to take parameters from $request->getQueryParams() .
Just explain to the API developers that for REST it's better to do this:
/games?start_from=2&limit=20 + header give all X-Pagination-* headers ... well, except perhaps Page-Count and Current-Page
Thus, if you have to change on the client the number of items per page, you don’t have to kick the API developers.
More on your problem. 7 requests is stupid. If you need to make a mechanism for caching data, for example, then yes, then we take all the data (although again, you can do this gradually, it all depends on the goals you are following) and store them periodically by invalidating the cache.
In general, it can be one request that receives the first portion of data and loads a new portion as needed. For example, if you have pagination implemented and you want everything to work as quickly as possible, you can, when scrolling the screen, if the user approaches pagination, immediately make a request for the next batch of data so that while the user clicks on the next button, the data would already be loaded. Well, or do an endless scroll. As already mentioned, it all depends on your use case. But still pass on recommendations regarding the API, because there will be problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question