Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Making an API call is like connecting to a database for data. You setup a connection, make a request, and receive results. Some requests require authentication, and results are primarily received in either XML or JSON.
Additional Resources
Getting Started with GitHub API Documentation
Authentication Types
There are 3 ways an API may allow a connection.
- Public Endpoints no authentication needed. Simply request a url and receive the results.
- Basic Authentication such as a username and password or other credentials.
- Token-based Authentication such as OAuth. The application asks to share specific information between the applications, and when the user chooses to grant permission, a token is stored on the user's machine.
Application programming interfaces, or
APIs, provide a method for connecting
0:00
your website to a third-party Web
service like Dropbox, Google, or GitHub.
0:05
It's kind of like connecting
to a database for data.
0:11
You set up a connection, make a request,
and receive the results.
0:13
These results are primarily
returned in either XML or JSON.
0:18
Both XML and JSON are human readable and
computer readable, and
0:23
just about any programming language comes
with standard libraries to parse XML and
0:28
JSON quickly and easily.
0:33
This promotes the easy
sharing of data on the web.
0:35
There is no single universal API.
0:39
Each site has its own, and
not all sites offer an API for you to use.
0:41
The first step for using any API
is to look up the documentation.
0:46
The documentation should tell you how to
connect, and what actions are available.
0:51
Let's take a look at the GitHub API.
0:56
Let's search for GitHub API.
0:58
Before using any API, you should make
sure to check the Terms and Conditions.
1:06
Make sure that your planned usage does
not violate the Terms of Service.
1:12
According to the GitHub API documentation,
all API access is over HTTPS,
1:19
and accessed from the api.github.com URL.
1:26
All data is sent and received as JSON.
1:31
There are three ways an API
may allow a connection.
1:35
First, an API can have a public endpoint
without any authentication needed.
1:38
Simply request a URL,
and receive the results.
1:44
Second, an API can allow basic
authentication, such as username and
1:48
password, or other credentials.
1:52
Finally, there's token based
authentication like OAuth.
1:55
The application asked to share specific
information between the applications.
2:00
And when the user chooses
to grant permission,
2:05
a token is stored on the user's machine.
2:08
GitHub supports all
three of these methods,
2:10
depending on what you're trying to do.
2:13
Although, most of the time,
2:16
GitHub requires that you pass at
least the username as the user agent.
2:17
You won't be able to read private data, or
2:21
update your account without
some sort of authentication.
2:24
Username alone is not enough.
2:28
For unauthenticated requests,
2:32
the rate limit allows you to
make up to 60 requests per hour.
2:34
Unauthenticated requests are associated
with your IP address, and
2:39
not the user making the request.
2:43
For a request using basic authentication,
or
2:45
OR, you can make up to
5,000 requests per hour.
2:48
Let's make our first request.
2:53
Launch the workspace attached to
this video, and open the console.
2:55
You can also use a terminal or
command line directly from your computer.
3:01
Using the console will allow us
to quickly test an endpoint.
3:05
Let's type curl
3:09
https://api.github.com /users,
3:12
and then /treehouse.
3:20
We receive a JSON feed of
the treehouse user information.
3:28
You can issue a get request to
the root end point to get all
3:33
the endpoint categories
that the API supports.
3:37
Let's go back to the documentation and
look at a few more endpoints.
3:47
GitHub gives us a lot more than just
user information including issues.
3:57
Projects, pull requests,
repositories and more.
4:02
Let's take a look at repositories.
4:07
We want to list user repositories.
4:12
Remember, you won't see private
repositories, unless you're authenticated.
4:15
Let's try the same treehouse request, but
this time, we'll add /repos to the end.
4:20
Now we receive a JSON feed
of public repositories.
4:33
Take some time to familiarize yourself
with some of the documentation and
4:37
endpoints that the good hub API supplies.
4:41
The Getting started section of
the guide is a great place to start.
4:44
You need to sign up for Treehouse in order to download course files.
Sign up