Skip to content

Commit

Permalink
add giphy-api
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelefavero committed Mar 6, 2024
1 parent 45a86b6 commit 67c708a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions giphy-api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<form onsubmit="search(event)">
<input type="search" />
<button type="submit">Search</button>
</form>

<div id="output"></div>

<script>
const input = document.querySelector('input[type="search"]')
const output = document.querySelector('#output')

// Search github users
async function search(event) {
event.preventDefault()

const query = input.value
const apiKey = 'frH3FGFrzZmYAmp3HssW0LhkW015UaHk'
const url = `https://api.giphy.com/v1/gifs/search?q=${query}&api_key=${apiKey}&limit=16`

const response = await fetch(url)

const data = await response.json()

output.innerHTML = data.data
.map((item) => {
return `
<img src="${item.images.original.url}" alt="${item.title}" />
`
})
.join('')
}
</script>
</body>
</html>

0 comments on commit 67c708a

Please sign in to comment.