Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

425
Visualizações
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

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?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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
  }
})

My general advice for using any REST API... always read the documentation specific to the resource you're consuming.


Sorting options for API results are limited to created, updated, pushed and full_name (default). If you want to sort by something else, you'll need to do that client-side, eg

data.sort((a, b) => a.stargazers_count - b.stargazers_count);
about 4 years ago · Juan Pablo Isaza Relatório

0

For GitHub, the correct property is per_page.

Just bear in mind that limiting results has nothing to do with Axios or any front-end tool. It is a backend implementation, and any backend developer is free to do it the way they want. Although there are some standards, such as cursor pagination.

In a real project, the backend and frontend developer would have a "contract" for how this would work, so both know how the property will work.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda