From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Incorporating fetch with async/await

Incorporating fetch with async/await - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Incorporating fetch with async/await

- [Instructor] We've talked about async, await and we've talked about fetch. Let's take a minute to look at how we can use all of these things together. So fetch by definition is asynchronous. We're waiting to get some data back. So let's go ahead and create a function called githubRequest. And this is going to be an async function that takes in the login name of a user of GitHub. And we're going to use await here. So we're going to await the results of a fetch. So the API that we're going to look at here is the GitHub API. So it's api.github.com/users, and then some sort of name. So I'm just going to use my own. You can use your own GitHub name if you'd like to. And we're going to make a request to this API. So now that I know that this is working, I'm just going to copy and paste this into our function. And instead of hard coding this for a specific user, we're going to take this in as an argument. So that login will be…

Contents