From the course: Introduction to Web APIs
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Use the response data in HTML - REST Tutorial
From the course: Introduction to Web APIs
Use the response data in HTML
- [Instructor] Now let's use the data to display the randomly chosen gif on our page. We want to create an image element. So I'm going to create a variable and I'll call this gifImg. To create an image element, I'm going to do document.createElement. And the element I want to create is an image element. IMG. Now we need to set the source attribute for this image. So gifImg.setAttribute. The attribute we want to set is the source attribute, src. And that's going to be equal to the Gif URL that we got. Okay, now let's put this image onto our page. So document.body.appendChild. And the element that we want to put on our page is our Gif image, gifImg. Okay, let's save this, go back into the browser and see our random gif. We'll refresh the page. Hey! Now that's a squirrel gif. And if you keep refreshing the page, you'll see a different randomly chosen squirrel gif. I could do this all day.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Authentication with an API key4m 42s
-
(Locked)
Make a request to the Giphy API4m 13s
-
(Locked)
Filter response with parameters2m 9s
-
(Locked)
Access data in the response2m 2s
-
(Locked)
Use the response data in HTML1m 15s
-
(Locked)
Challenge: Explore the Giphy API1m 24s
-
(Locked)
Solution: Explore the Giphy API1m 50s
-
(Locked)
-
-
-