Skip to content

Instantly share code, notes, and snippets.

@Tribhuwan-Joshi
Created September 16, 2022 11:26
Show Gist options
  • Save Tribhuwan-Joshi/322102264f2298d52d0a0afb9a0a8d7f to your computer and use it in GitHub Desktop.
Save Tribhuwan-Joshi/322102264f2298d52d0a0afb9a0a8d7f to your computer and use it in GitHub Desktop.
API to get gifs
<!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>Document</title>
</head>
<body>
<img src="#" alt="gif">
<button>Refresh</button>
<script>
const img = document.querySelector('img');
function run(){
fetch('https://api.giphy.com/v1/gifs/translate?api_key=T7ziYgAkCNMJhQXUhjjc4siv7Tamvcb7&s=cats', { mode: 'cors' })
.then(function (response) {
return response.json();
})
.then(function (response) {
img.src = response.data.images.original.url;
});
}
const btn = document.querySelector('button');
btn.onclick = run;
run();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment