Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to limit the axios get request results

I am trying use an axios request to fetch data from github api, but for some reason _limit is not returning the limited number of results?

await axios.get(`https://api.github.com/users/freeCodeCamp/repos?_limit=10`)
            .then(
                (res) => {
                    console.log(res.data);
                    
                }
            )

The following http request is working perfectly by limiting the results

https://jsonplaceholder.typicode.com/todos?_limit=2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Whereas the following http request is not limiting the data

https://api.github.com/users/freeCodeCamp/repos?_limit=2

What’s the difference between the above two requests?

>Solution :

The _limit parameter you see in https://jsonplaceholder.typicode.com is specific to their json-server software.

From the Github REST API documentation, you want to use the per_page parameter

const { data } = await axios.get("https://api.github.com/users/freeCodeCamp/repos", {
  params: {
    per_page: 10
  }
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading