How to parse link header from github API

toxinlabs picture toxinlabs · Jan 5, 2012 · Viewed 15.7k times · Source

the github API sends the pagination data for the json results in the http link header:

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

since the github API is not the only API using this method (i think) i wanted to ask if someone has a useful little snippet to parse the link header (and convert it to an array for example) so that i can use it for my js app.

i googled around but found nothing useful regarding how to parse pagination from json APIs

Answer

Kevin Sawicki picture Kevin Sawicki · Jan 7, 2012

There is a PageLinks class in the GitHub Java API that shows how to parse the Link header.