This course will be retired on June 1, 2025.
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
How does the web work? What happens when we click on a link? How can we get weather data from a website into an Android app?
Definitions
- HTTP: HyperText Transfer Protocol
- GET: Retrieve data from the network
- POST: Create new data over the network
- CRUD: Create/Retrieve/Update/Delete
Additional Information
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
[SOUND] Since you're watching this video,
you're obviously an internet pro.
0:02
Have you ever wondered how
it actually works though?
0:08
What's the deal with
the HTTP portion in URLs?
0:12
What actually happens
when you click on a link?
0:16
[SOUND] HTTP stands for
HyperText Transfer Protocol.
0:18
Simply put,
0:22
this is the protocol that allows us
to communicate over the Internet.
0:23
We'll see a concrete example shortly,
but I think it's useful to have
0:28
a basic understanding of how sending and
receiving data over the web works.
0:32
That being said,
this isn't a deep dive into HTTP.
0:37
It can be confusing and
overwhelming for me too.
0:42
So don't worry if you also feel under
the clouds with these concepts.
0:45
The Request/Response Model
of computing powers the web.
0:49
What this means is that we make a request
to a certain place, in a certain format.
0:53
The place is accessed by an identifier,
which we usually refer to as a URI,
0:58
or uniform resource identifier,
most commonly with webpages.
1:05
The URI is the web address or URL.
1:10
Notice the word address in web address,
that's not an accident.
1:14
The URL is like the address for
a building.
1:19
It's where you'll find the resource.
1:22
I've included some information
in the teacher's notes,
1:24
if you'd like to read more about URIs and
URLs.
1:26
We send a request to a specific location.
1:30
The request is the first
half of the process.
1:33
The second half is the response
from that location, or URI.
1:35
This was the process we
talked about previously,
1:41
when we discussed the Dark Sky API.
1:44
This is a rather simplified discussion,
which for our purposes is fine,
1:47
as the details of how a network
sends bytes and bits back and
1:51
forth are obstructed away from us.
1:55
Modern programming involves
adding layers of abstraction.
1:58
Each layer of abstraction
makes it easier for
2:02
us to concentrate on the higher
level tasks we are concerned with.
2:05
Prior to these levels of abstraction,
2:09
we would have to worry about
how to send the bits ourselves.
2:11
That can be a real headache.
2:14
Why is all this important to us and
our Stormy app?
2:16
Well, we are getting ready to
request some data from Dark Sky,
2:19
and we do so with an HTTP GET request.
2:23
Programming is truly about working with
data that can be boiled down to four basic
2:27
operations, creating data, reading or
2:31
retrieving data once it's been created,
updating the data, and deleting it.
2:35
You'll often hear these basic operations
referred to by their acronym, CRUD.
2:40
HTTP has its own operations that
correspond to this CRUD, as we see here.
2:46
Most web programming primarily deals with
two of these operations, POST and GET.
2:52
Since we aren't creating
a weather forecast with Stormy,
2:57
we won't worry about the POST method.
3:01
However, we will be using GET requests
to retrieve or read data from a server.
3:03
Whenever we visit a website,
our browser issues an HTTP GET request to,
3:10
well, request the latest
version of a webpage,
3:15
video, weather forecast, or
whatever it is we are wanting to view.
3:18
I've put additional information in
the teacher's notes about HTTP methods for
3:23
further reading.
3:27
Android clients are no different.
3:29
We will be making an HTTP GET
request to the Dark Sky API servers.
3:32
Using the URI in the developer's
documentation we've previously looked at,
3:37
we send a request with
the exact information we want.
3:42
The servers then send a response
that includes the weather data.
3:45
It's up to us then to handle the data we
receive and use it in our application.
3:49
If we use the web browser example, the
server sends back a response with HTML,
3:53
and the browser converts it
to a webpage we can view.
3:59
Recall that this is the power of the
interface portion of the API in action.
4:03
We don't need to know how
Dark Sky gets their data,
4:08
as long as we get back a response
in an agreed upon format.
4:11
Sounds easy enough, right?
4:16
Well, as you might have guessed, it isn't
quite as simple as I've made it out to be.
4:18
Sure, those basic concepts hold true.
4:24
But we're going to have to
learn how to create and
4:27
send a web request, receive a response,
and handle the response.
4:29
We'll need to think about what happens if
we get an error in the response as well.
4:33
Additionally, we need to make sure we
are performing these types of requests
4:38
in the background,
to ensure our app remains responsive.
4:42
Before we jump into our project again,
4:46
let's discuss networking as it applies
to mobile devices in the next video.
4:49
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up