From the course: Introduction to Web APIs
Unlock the full course today
Join today to access over 25,000 courses taught by industry experts.
Loop through the response data - REST Tutorial
From the course: Introduction to Web APIs
Loop through the response data
- [Instructor] Let's do something a little more practical and robust with the data. We're going to display all the H+ Sport products with their name and photo. It's very similar to what we just did. We want to get a specific property from the response and set it equal to a newly created HTML element. But we're going to do all this inside of a for in loop. So let's go back in to our code and write this out. First, I'm going to delete some of the code we wrote in the previous video so we can start fresh. I'm also going to remove the quantity parameter since we want to see all of the products. So in the response, let's delete the quantity parameter. First, I'm going to write a four in loop, so for, parentheses, and then we'll choose a variable name to iterate through all of our JSON data. I'm going to call this variable items in our jsonData and then curly brackets. And now we can write what we want to do in this for loop.…
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)
API documentation2m 23s
-
(Locked)
Make a request to the API2m 36s
-
(Locked)
Filter the response with parameters3m 54s
-
(Locked)
Access data in the response2m 38s
-
(Locked)
Use the response data in HTML1m 47s
-
(Locked)
Loop through the response data4m 28s
-
(Locked)
Challenge: Display data on a webpage42s
-
(Locked)
Solution: Display data on a webpage1m 41s
-
(Locked)
-
-
-
-