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

169
Visualizações
How do I fetch more than one ID in an API endpoint that only supports one ID per request?

I'm using Coingecko API for price data and time (Unix) to output this in a chart, but the endpoint I'm using only supports one ID per request.

document.onreadystatechange = async () => {
  if (document.readyState === "complete") {
    const coin = "bitcoin";
    const currency = "brl";




const response = await fetch(

  `https://api.coingecko.com/api/v3/coins/${coin}/market_chart?vs_currency=${currency}&days=10&interval=hourly
  `
);

const data = await response.json();



const prices = data.prices.map((e) => e[1]);
const date = data.prices.map(i => i[0]);

i need that the function do the same also for solana, cardano, ripple, dash and litecoin

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

0

If your API only supports one ID per request, and you need multiple IDs, you're going to need to make multiple requests.

One way to do them in parallel and wait for all to complete before continuing would be

const data = await Promise.all([
    fetch(endpoint1).then(response => response.json()), 
    fetch(endpoint2).then(response => response.json()), 
    fetch(endpoint3).then(response => response.json())
]);

The above will result in data containing an array of the responses for each endpoint -- data[0] will be the json from endpoint1, data[1] from endpoint2, and so forth. You'll need to step through them to get your prices and dates for each of the IDs (obviously it wouldn't make sense for the Promise.all() to try merging all the responses into one, because you'd have no way of knowing which price went with which ID.)

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