Fetching data is a common task that Promises help you manage more effectively. Take a closer look at an HTTP request as you resolve or reject the data that you request in this video.
- [Instructor] We often use promises to load data. … Let's create a function called spacePeople … that returns a promise … and we'll call it spacePeople … because it's going to fetch some data … from an API of astronauts who are currently in space. … So spacePeople again will return a new Promise. … It's going to have resolve and rejects … as the arguments here. … We also are going to create a link to an API. … So we'll use this open-notify astronaut API. … And then we need to build a request. … So we're going to create another variable called request. … This is going to be equal to a new XML HTTP request. … Now, when we open this request, … we're going to send it as a GET request. … In other words, we're going to ask for some data … from this API. … When the request loads, … we're going to set it to this function. … So if the status is 200, meaning everything is going well, … so we'll just parse the response here on line nine. … Otherwise, in other words, if the status is something else, …
This course was created by Eve Porcello. We are pleased to offer this training in our library.
- What is ECMAScript?
- Writing and searching strings
- Writing maps
- Destructuring arrays
- Searching arrays
- Creating objects
- Destructuring objects
- Iterating with the for/of loop
- Getting and setting class values
- Using ECMAScript functions
- Building and returning promises
- Using async/await syntax
Skill Level Intermediate
1. What Is ECMAScript?
What is ECMAScript?1m 44s
2. ECMAScript Variables and Data Structures
3. Arrays and Array Methods
Destructuring arrays1m 34s
4. ECMAScript Objects
5. ECMAScript Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.