Hi, we use PhlyRestfully and now Apigility since several years ;-).
We often need to call a Web Service to count a number of entities. The HAL standard and zf-hal allow to get a count very easily using the total_items property of the fetched HAL collection.
For example...
GET https://myserver.com/comments?page=1&page_size=1
{
"_links": { ... },
"_embedded": {
"comments": [ ... ]
},
"page_count": 45,
"page_size": 1,
"total_items": 45,
"page": 1
}
Then on the client side its very simple (sample in JS / jQuery here).
$.get(url, function(payload) { console.log(payload.total_items); });
It works, but I think this is "sub-optimal" because the library forbid page_size values equal to 0 (see
|
if ($size < 1 && $size !== -1) { |
).
In our case its has the following consequences
- This forces an additional request in our database to always fetch at least one entity ;
- It increases the size of the returned payload.
So, why the page_size parameter cannot be equal to 0 ? If their are good reasons what the best practices to count entities efficiently with REST / HAL ? If their are no good reasons could it be possible to authorize page_size 0 values ?
Thanks
Hi, we use PhlyRestfully and now Apigility since several years ;-).
We often need to call a Web Service to count a number of entities. The HAL standard and zf-hal allow to get a count very easily using the
total_itemsproperty of the fetched HAL collection.For example...
Then on the client side its very simple (sample in JS / jQuery here).
It works, but I think this is "sub-optimal" because the library forbid
page_sizevalues equal to0(seezf-hal/src/Collection.php
Line 295 in 7c164ef
In our case its has the following consequences
So, why the
page_sizeparameter cannot be equal to0? If their are good reasons what the best practices to count entities efficiently with REST / HAL ? If their are no good reasons could it be possible to authorizepage_size0 values ?Thanks