views:

89

answers:

3

Hi guys,

we are having a search/list-resource:

http://xxxx/users/?page=1

Internally the page-size is static and returns 20 items. The user can move forward by increasing the page number. But to be more flexible we are now thinking also to expose the size of a page:

http://xxxx/users/?page=1&size=20

As such this is flexible as the client can now decide network-calls vs. size of response, when searching. Of course this has the drawback that the server could be hit hard either by accident or maliciosly on purpose: http://xxxx/users/?page=1&size=1000000

For robustness the solution could be to configure an upper limit of page size (e.g. 100) and when it is exceeded either represent an error response or a HTTP redirect to the URL with highest possible page-size parameter.

What do you think?

+1  A: 

Managing access to resources is always a good idea aka protecting outside interfaces: in other words, put a sensible limit.

The redirect might be a good idea when it comes to development time i.e. when the user of the API gets acquainted with the service but outside of this situation, I doubt there is value.

Make sure the parameters are well documented either way.

jldupont
+3  A: 

Personally, I would simply document a maximum page size, and anything larger than that is simply treated as the maximum.

Nate Bross
A: 

Have you tested this to see if it's even a concern? If a user asks for a page size of a million does that really cause all your other requests to stop/slow? If so I might look at your underlying architecture first. But if, in the end, this is an issue I don't think setting a hard limit on page size is bad.

Question: When I user GETs the URI http://xxx/user?page=1 does the response have a link in it to the next page? previous page? If not then it's not really RESTful.

Gandalf
i am more worried that unneccessary high payload is generated and bandwidth is wasted. sure the application won't crash, but it will cause unneccessary load on the search backend and on the xml/json response-building. in my view sending size=1000000 is rather weird and is either accident or malicious. sure, paging-links are included :)
manuel aldana
Understood - but for someone doing data mining or other actions that need a large data set I can see it happening. Honestly I'd throw a Bad Request (400), with an error message stating the maximum page size. Returning some server defined number of items will look to the user like they asked for 100000 but got 200, which they will probably think means that there are only 200 items to be found.
Gandalf
If you are returning next/previous paging links it should be clear that there is more data.
Nate Bross
@Nate - first rule of design, never assume anything. Almost every time I see a confused user I see a programmer somewhere saying "it's obvious".
Gandalf