Skip to content

Instantly share code, notes, and snippets.

@urielhdz
Created September 17, 2022 17:40
Show Gist options
  • Save urielhdz/878e83e21fb09d637117c6030f67aefa to your computer and use it in GitHub Desktop.
Save urielhdz/878e83e21fb09d637117c6030f67aefa to your computer and use it in GitHub Desktop.
Consumir la API de dev.to
// https://dev.to/api/articles?username=iamluisj
// AJAX => Asynchronous JavaScript and XML
// XMLHttpRequest
// fetch
async function cargarPublicaciones() {
let respuesta = await fetch('https://dev.to/api/articles?username=uriel_hedz');
let jsonArticulos = await respuesta.json();
return jsonArticulos;
}
let contenedor = document.querySelector("#publicaciones");
cargarPublicaciones().then(function(jsonArticulos){
jsonArticulos.forEach(function(articulo){
// title, description, url
let nodoArticle = document.createElement("article");
nodoArticle.innerHTML = `
<h2>${articulo.title}</h2>
<p>${articulo.description}</p>
<a href="${articulo.url}"> Ver el artículo </a>
`;
contenedor.appendChild(nodoArticle);
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Práctica </title>
</head>
<body>
<div id="publicaciones"></div>
<script src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment