Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
Making GET Request to dockerhub v2 API via Javascript

I want to show some Dockerhub image statistics on a website. To acomplish this, i tried making an GET Request to my dockerhub Repo, which when visited should get me a json file, that contains the data i need.

The GET request should go here: https://hub.docker.com/v2/repositories/freddy0/crafty-container/

Currently i got this working

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

Which when called on a local .json file returns the pul count just fine

when i try to acess the json via the javascript file i made i get some errors, which i am seemingly not able to fix

This is my fetch code, which is simply copied from chrome dev tools > resource > copy as fetch

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

I also tried this, which also returns noting

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();

The Errors i get range from CORS policy denied to 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.

When trying to get data via a different source i recieve a valid answer which i could work with : https://reqbin.com/0mfci8tl

Anyone got an idea how to accomplish this?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda