hyperoslo / api-playbook

A place to define the conventions we use to build APIs
4 stars 1 forks source link

Consider `Link` header for pagination #7

Open fespinoza opened 9 years ago

fespinoza commented 9 years ago

https://developer.github.com/v3/#pagination

http://tools.ietf.org/html/rfc5988

this is the way github handles pagination on their APIs, they use pagination in the url as query parameter, then use the Link header to inform the next page url and the previous page as well

Link: <https://api.github.com/user/repos?page=3&per_page=100>; rel="next",
  <https://api.github.com/user/repos?page=50&per_page=100>; rel="last"
jgorset commented 9 years ago

I much prefer this approach to having, say, data and meta objects in the JSON eveywhere. :+1: from me!

sindrenm commented 9 years ago

I would actually prefer adhering to RFC 7233 for pagination. It provides multiple headers and is a different approach to pagination than just “pages”. It also looks a lot better in the headers, in my opinion. Super simple to set up using Rails with the clean_pagination gem as well.

sindrenm commented 9 years ago

Have a look at how we did this in HyperAdmin: https://github.com/hyperoslo/hyper_admin/commit/4da49c000d388da593a4cea2327f5da53ec9ec43