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
The Dark Sky API is a RESTful API, which means that we can use the API via a simple identifier, a URL.
Update
The Dark Sky API is no longer accepting new signups.
You can follow along with a similar API like AccuWeather. Learn about other popular weather API options in this Treehouse Community post.
When we're working with APIs,
we care a lot about the interface itself.
0:00
It's an understanding between the user,
us, and the service, Dark Sky.
0:04
It's much like a contract.
0:10
It tells us what we need
to provide to the service.
0:12
In exchange,
it tells us what the service will return.
0:16
The rest of the details, like where
they get the weather information,
0:20
how they manage it,etc,
is hidden from us, which is fine.
0:24
Let's take a look at the Dark Sky API,
and see how to use their latest version.
0:29
We care about this one here,
the Forecast Request.
0:33
The Forecast Request returns current
weather data, along with forecast date for
0:37
the next hour, 48 hours,
and the next week.
0:41
This is more or less the interface
we will be using for our Stormy app.
0:45
We'll need to do a bit of work,
of course, but don't worry,
0:50
it isn't going to stretch us too much, and
I'll walk you through it step by step.
0:53
Essentially, we are going to
make a request at this URL and
0:57
then handle the response
Dark Sky provides.
1:01
We'll dive into that in more detail soon.
1:04
The Dark Sky API is a web API that follows
the common RESTful programming pattern.
1:08
REST stands for
1:14
Representational State Transfer,
which in it of itself may not mean much.
1:16
In our context, it means that when an API
adheres to the principles of REST,
1:22
it doesn't require us, the client,
to know anything about the specific
1:26
structure of the API,
it's another black box, if you will.
1:31
A RESTful API provides
whatever information
1:36
the client needs to interact
with by means of an identifier.
1:39
In most cases, this is a URL.
1:43
A URL is a reference to a resource like
1:47
http://www.google.com, or
1:51
in our case here, the special URL that
will give us a specific weather forecast.
1:56
RESTful programming isn'tt necessarily
restricted to the web, but
2:02
most web-based APIs are built
following the RESTful pattern.
2:06
In our case, our client, the Stormy app,
2:11
doesn't know anything at
all about the Dark Sky API.
2:14
We simply request the data we
need through an exposed URL
2:18
with certain keywords that
specify what data we want back.
2:22
The API then returns this data to our
client in a specified format, XML,
2:26
JSON, or some other data format.
2:31
In the case of Dark Sky, we see JSON data,
2:34
which is part of the contract
the API establishes with the client.
2:37
With a RESTful API,
that's the only real restriction.
2:41
The client and server need to agree
on the data format being used.
2:45
JSON data is very common for
web APIs to provide.
2:49
And that's what we'll use in this course.
2:53
Returning to the Dark Sky API
documentation, if we look at this URL
2:56
under Forecast Request, we see how we
need to construct the request to the API.
3:00
The URL has this base component
of api.darksky.net/forecast,
3:04
and then needs specific identifiers,
such as a private API key,
3:10
and the longitude and
latitude coordinates, for our location.
3:15
But wait, a private API key?
3:20
What's that all about?
3:23
We'll need to register for
a Dark Sky developer account so
3:25
we can get an API key and
use this service.
3:28
We click on the Sign Up button up at
the top of the page, we can register.
3:31
It's super simple, and all you need to
provide is an email address and password.
3:35
I'll put the link in the Teacher's Notes,
if you need it as well.
3:40
Once you're registered, you'll see
a request to provide billing information.
3:43
We can ignore that because we'll
utilize their free service tier.
3:47
The free tier allows 1,000 requests a day.
3:51
This will be plenty for our purposes.
3:54
If you decide to publish
your app on the Play Store,
3:56
you'll probably want to
upgrade to the paid tier.
3:59
Great, once you've register with Dark Sky,
4:02
join me in the next video
where we'll start our project.
4:05
You need to sign up for Treehouse in order to download course files.
Sign up