Since handling HTTP requests is such a common task, browsers have implemented fetch which allows you to make a request and return some data. In this video, make a fetch request to an API and handle the response.
- [Instructor] Remember our spacePeople function … from the previous video … that went and got some data from an API? … It works pretty well … but we're going to reformat this request … and instead, use something called fetch. … Fetch is a function that works natively in the browser. … There are also packages that work with Node … like node-fetch and isomorphic-fetch … so you can use something similar … in that environment as well. … Fetch is just going to take in the URL … of our API. … So that api.open-notify.org/astros/json, … that's where all of our data is. … So we're going to pass that directly into this fetch function. … Then we're going to chain on .then … and we're going to console.log … whatever the response is. … Now, fetch returns the entire response object. … And the object has a JSON function … that parses the body as JSON. … So let's go ahead and take the response … and we'll call it response.json. … Then we're going to console.log everything. … So this is going to log the same exact thing …
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.