

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Communicating on the Web
incomplete
2: HTTP Requests and Responses
incomplete
3: HTTP Powers Websites
incomplete
4: HTTP URLs
incomplete
5: Using URLs in HTTP
incomplete
6: Requests and Responses Quiz
incomplete
7: JavaScript's Fetch API
incomplete
8: Web Clients
incomplete
9: Web Servers
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In this course, we'll be using JavaScript's built-in fetch API to make HTTP requests. We already used it in the last two assignments!
The fetch function is made available to us by the JavaScript language running in the browser, all we have to do is provide it with the parameters it requires.
const response = await fetch(url, settings);
const responseData = await response.json();
We'll go in-depth on the various things happening in this standard fetch call later, but let's cover some basics for now.
response is the data that comes back from the serverurl is the URL we are making a request tosettings is an object containing some request-specific settingsawait tells JavaScript to wait until the response comes back from the server before continuingawait waits for response.json() to convert the response data from the server into a JavaScript objectFix the bug in the code.
The problem is that we aren't waiting for the response to come back before continuing with our code. We're calling .json on a pending Promise instead of the actual response.
More on this magical .json method later.