I want to implement this API into my website so I can get random memes from reddit.
The API was made by D3vd on github (https://www.github.com/D3vd/Meme_API)
The response I get from https://meme-api.herokuapp.com/gimme/memes (the api) looks something like this:
{
"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"]
}
How do I get only the image link ("url") with javascript, so that I can display it on my website?
thx in advance
CodePudding user response:
Some very basic ajax code using fetch should suffice:
fetch('https://meme-api.herokuapp.com/gimme/memes')
.then(r=>r.json())
.then(json=>{
console.log( json.url )
})