Friday, 28 April 2017

Github api paging info from fetch or request(nodejs)

I am trying to get the data from github repos api using JavaScript. I am using fetch to get the data on client side, but I am open to do the same from server side with request module.

My code looks like this:

 fetch(`https://api.github.com/users/${username}/repos?page=${number}&per_page=${length}`)
       .then(res => res.json())
       .then((result) => { 
             //do something
    }

If I request this url with postman like:

https://api.github.com/users/angular/repos?per_page=10

I can see the link header as:

<https://api.github.com/user/133426/repos?per_page=10&page=2>; rel="next", <https://api.github.com/user/133426/repos?per_page=10&page=17>; rel="last"

How do I read this link header in JavaScript, (Node or front-end). All of the examples I saw on the internet are related to Ruby or PHP. Can anyone guide me on how to use these with my current implementation?

Thanks.



via brittany

No comments:

Post a Comment