I'm building an api and a bit into the development I realized that I constantly change the order of the page
and pageSize
parameters.
Currently I use C# and javascript, so the method declaration looks something like this:
public IEnumerable<Order> Get(int pageSize = 9, int page = 1, string name = null)
And the client code:
this.get = function (name, pageSize, page) {
// Do stuff..
}
But a lot of the times I've ended up writing:
name, page, pageSize // note that page is before pageSize.
And it also has an http endpoint, which currently looks like this (with pageSize
first):
www.example.org/api/orders/9/1
Or should it look like this (with pageSize
last):
www.example.org/api/orders/1/9
What's the logical way to call an api? By setting the page
first, or pageSize
first? Is there a best (or common) practice?
Argument for setting pageSize
first:
- The consumer may simply define the number of items to fetch without setting the page.
Argument for setting page
first:
- The consumer may simply shift page and rely on the servers pageSize.
www.example.org/api/orders?pageSize=9&page=1
and problem solved here. Otherwise it wouldn't really matter that much, my opinion for what it's worth: First define the thing (pageSize) then number the things (page to use).