Created
September 17, 2022 17:40
-
-
Save urielhdz/878e83e21fb09d637117c6030f67aefa to your computer and use it in GitHub Desktop.
Consumir la API de dev.to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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