Skip to content
Advertisement

How to parse link header from github API

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

JavaScript

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

Advertisement

Answer

The parse-link-header NPM module exists for this purpose; its source can be found on github under a MIT license (free for commercial use).

Installation is as simple as:

JavaScript

Usage looks like the following:

JavaScript

…after which one has parsed.next, parsed.last, etc:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement