5

I am interfacing with Shopify and they use RESTful API. When I request a resource that returns an array of items, they use RFC8288 pagination format.

For example, https://example.com/api/inventory_levels.json?limit=10 returns 10 entities along with the following response header:

Link: <https://example.com/api/inventory_levels.json?limit=10&page_info=eyJs9pZHMiO>; 
rel="previous", <https://example.com/api/inventory_levels.json?limit=10&page_info=MiZHeyJs9pO>; rel="next"

Appearantly if I want to retrieve all entites from that resource I need to iterate through the 'next' URL until there's no more 'next' returning. But how am I going to parse these info using JAVA or C# code? I could use a regular expression like <(?<next_url>.*)>; rel="next" to retrieve the 'next_url' from it. But it feels like re-inventing the wheel and not robust.

If this is a well-defined feature, shouldn't there be a readily available library/infrastructure that could be used? I just don't want to be caught by surprise if one day the formatting shows up different (like having an extra space and such) and, whilst abiding to the RFC defination, breaks my hastily scrambled up RegEx solution.

Suggestion welcome for Java or C#.

Lionet Chen
  • 832
  • 11
  • 26
  • I'm looking for a solution to this for C# as well. Have you figured it out yet by chance? – Lukas Oct 02 '20 at 15:22
  • @Lukas Just use the RegEx I provided in my question and retrieve the `next_url` field from the match result. It is not a framework level solution but it is proven to work, at least in my case. – Lionet Chen Oct 05 '20 at 23:36

0 Answers0