-
This project was made as a part of Springboard's Software Engineering Course. The main objective of the project was to use
Axiosto make an externalAPIcall to add new elements to the page via theDOM Object.- NOTE: This page uses a beta
APIkey.
- NOTE: This page uses a beta
-
Link for live application (hosted through GitHub Pages).
HTMLCSSJavascriptAxios(CDN)
-
searchGif([SEARCH_TERM])async function searchGif(search) { try { const api_key = YOUR_API_KEY; const res = await axios.get('https://api.giphy.com/v1/gifs/search', { params: { api_key, q: search, limit: 15 } }); const mainDiv = document.querySelector('#content-row'); const rand = randInt(); const resObj = res.data.data; const imgSrc = resObj[rand].images.original.url; const newDiv = document.createElement('div'); newDiv.classList.add('col-md-4', 'mx-auto'); const newImg = document.createElement('img'); newImg.classList.add('m-2', 'rounded', 'shadow'); newImg.src = imgSrc; newDiv.append(newImg); mainDiv.append(newDiv); } catch (e) { alert('ERROR: Search field MUST be filled out!'); } }
- Function will accept a
Stringand use that string to make a call viaAxiosto theGiphy API. - Once the
promiseis resolved, the main content area is selected, a new image object is created from theURLreturned from the response. - The new image is then added to the web page for display.
- Function will accept a
-
randInt()function randInt() { let rand = Math.floor(Math.random() * 15); return rand; }
- Function's main responsibility is to generate a random number between 1-15 which will be called in the function from above.
- Once the random number is generated, we will select an image from the returned
promisewith said random number.
-
formanddeleteBtnare the main variables that the application will use to input the results received from the Giphy API.-
formis listening for submission events and once a search term is added, the page will wipe theinputsection via theDOM Objectto mimic the page being reloaded. -
deleteBtnis listening for a click on this button and once it is clicked, all items on the content section will be removed from the page view.
-