Quiero implementar esta API en mi sitio web para poder obtener memes aleatorios de reddit.
La API fue creada por D3vd en github ( https://www.github.com/D3vd/Meme_API )
La respuesta que recibo de https://meme-api.herokuapp.com/gimme/memes (la api) se ve así:
{ "postLink": "https://redd.it/sg8j7b", "subreddit": "memes", "title": "No you respect the nature now!", "url": "https://i.redd.it/nk9eiy1nnte81.jpg", "nsfw": false, "spoiler": false, "author": "Abdul_Sbeei", "ups": 423, "preview": ["https://preview.redd.it/nk9eiy1nnte81.jpg?width=108\u0026crop=smart\u0026auto=webp\u0026s=253fc41547e5acc1ee3efcc0a4644e8d52d67181", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=216\u0026crop=smart\u0026auto=webp\u0026s=6050660429dd3a4ae6699a0f42294c04fc1fae02", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=320\u0026crop=smart\u0026auto=webp\u0026s=07ff549bbd76d2f25f509cece0149e7939427edd", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=640\u0026crop=smart\u0026auto=webp\u0026s=baa9e058ba9722515aefa9ab28bb95235d0e151b"] }¿Cómo obtengo solo el enlace de la imagen ("url") con javascript, para poder mostrarlo en mi sitio web?
gracias de antemano
Un código ajax muy básico que use fetch debería ser suficiente:
fetch('https://meme-api.herokuapp.com/gimme/memes') .then(r=>r.json()) .then(json=>{ console.log( json.url ) })