Pagination preferences (i.e. Link or envelope)

68 views
Skip to first unread message

Usman Ehtesham

unread,
Jul 8, 2017, 6:50:26 PM7/8/17
to API Craft
Hello,

I have reading about best practices for Restful API esp about versioning and pagination. I wanted some input on how to return paginated responses for Restful APIs. I have read about two ways of doing it:
1) Add info like next, previous in the Link Header
2) Enveloping your response so that you can have a sub-dictionary in the response that will have pagination info (for e.g. {'data': {}, 'pagination': {'next': '', 'prev': ''}}


What is your preference/opinion?

Peter Williams

unread,
Jul 10, 2017, 7:12:01 PM7/10/17
to api-...@googlegroups.com
I generally use a hypermedia format such as JSON-LD or HAL and implement each collection as a resource of its own using `item` links to indicate membership (per https://tools.ietf.org/html/rfc6573). If the collection is paginated i prefer `next` and `prev` links to provide the exact urls of those respective pages in the response body.

Link headers are a little too subtle for my taste.  They are easily overlooked which can lead to confusion.

Peter




--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

Ismael Celis

unread,
Jul 11, 2017, 12:56:30 PM7/11/17
to API Craft
I use HAL, mostly

"_links": {
  "next": {"href": "https://..."},
Reply all
Reply to author
Forward
0 new messages