You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

I've used a number of other application API's that followed the JSON organizations standard v1.0 (http://jsonapi.org/format/).

There is one component of this specification that I have found particularly useful, and that is the pagination specification (http://jsonapi.org/format/#fetching-pagination)

Having recently used Clowders pagination on search results, I felt it might improve usability to consider adopting the JSON standard approach.

Specifically adding a "links" section like below...


"links": { 
        "self": "http://example.com/articles", 
        "next": "http://example.com/articles?page[offset]=2", 
        "last": "http://example.com/articles?page[offset]=10" 
}

The example uses offsets, but could just as easily been a "from-to" pattern. 

The nice thing about this is that it simplifies the approach the consumer must implement to page through the results.  They typically make the first call with a "priming" fetch that specifies a number of results to return (eg. page=25) or (eg.  From=1&To=25).  After that they don't have to keep track of any counters, they can just use the links provided in the result set for further navigation.

If there isn't a "previous" or "first" then you are at the beginning.  If there isn't a "next" or "last" then you are at the end.  For me, the "self", "first" and "last" are not as useful but I can imagine for some they are.

  • No labels