Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Hacer una solicitud GET a la API de dockerhub v2 a través de Javascript

Quiero mostrar algunas estadísticas de imágenes de Dockerhub en un sitio web. Para lograr esto, intenté hacer una solicitud GET a mi dockerhub Repo, que cuando se visita debería obtener un archivo json que contiene los datos que necesito.

La solicitud GET debe ir aquí: https://hub.docker.com/v2/repositories/freddy0/crafty-container/

Actualmente tengo este trabajo

 function dockerPulls(image){ var data = JSON.parse(image); return data.pull_count; }

Que cuando se llama en un archivo .json local devuelve el conteo de pul muy bien

cuando trato de acceder al json a través del archivo javascript que hice, recibo algunos errores, que aparentemente no puedo solucionar

Este es mi código de recuperación, que simplemente se copia de las herramientas de desarrollo de Chrome > recurso > copiar como recuperación

 fetch("https://hub.docker.com/v2/repositories/freddy0/crafty-container/", { "headers": { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7", "cache-control": "no-cache", "pragma": "no-cache", "sec-fetch-dest": "document", "sec-fetch-mode": "navigate", "sec-fetch-site": "none", "sec-fetch-user": "?1", "sec-gpc": "1", "upgrade-insecure-requests": "1" }, "referrerPolicy": "strict-origin-when-cross-origin", "body": null, "method": "GET", "mode": "cors", "credentials": "include" });

También probé esto, que también devuelve notando

 var url = "https://hub.docker.com/v2/repositories/freddy0/crafty-container"; var xhr = new XMLHttpRequest(); xhr.open("GET", url); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { console.log(xhr.status); console.log(xhr.responseText); }}; xhr.send();

Los errores que obtengo van desde la política CORS denegada hasta net::ERR_FAILED, Access to XMLHttpRequest at 'https://hub.docker.com/v2/repositories/freddy0/crafty-container/' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Cuando intento obtener datos a través de una fuente diferente, recibo una respuesta válida con la que podría trabajar: https://reqbin.com/0mfci8tl

¿Alguien tiene una idea de cómo lograr esto?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!