Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 833 of the free egghead.io lessons, plus get Tools content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Review final screencast result

1:23 Tools lesson by and

Our lesson has been planned, recorded, and edited. It’s ready to be uploaded to egghead.io! Victory dance. Let’s see how it all turned out.


egghead.io comment guidelines

Avatar
egghead.io

Our lesson has been planned, recorded, and edited. It’s ready to be uploaded to egghead.io! Victory dance. Let’s see how it all turned out.

We're ready to upload our lesson to egghead.io. Let's see what the finished product looks like. First let's type consturl, and let's set that equal to the GitHub API, so that's api.github.com/users, and then we need some sort of user here. Now let's type constuser = some GitHub user name, which if we use mine, that's TrevorDMiller.

Now we can use the global fetch function by saying fetch and then passing it our URL. This function will return a promise, so we can say .then and when this promise resolves, it will contain our response. We'll say response, and now inside of this function we can say response.json to convert our response into JSON.

Now let's type .then, we'll have our JSON data. Let's console log out the type of the GitHub account. We see we have the type of user, because the TrevorDMiller GitHub account is of type user. If we go back up to our user string here and use Facebook, we now see that Facebook is of type organization.

Now let's go down and type .catch and this will be used if we get an error. We will get our error, and we can use that error. Let's just log out the error in this case. Let me turn off my network connection. Now we get this type error, failed to fetch.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?