Web
Some examples for today are available here:
https://github.com/cs125-illinois/lecture-webapis-examples
Feel free to fork!
Enjoy Break
Web APIs Web Internet
-
Before we can talk about web APIs, we first have to talk about the web…
-
…and before we can talk about the web, we have to talk about the internet.
-
Which is great, because I love the internet!
What is the internet?
Internet As Wired Infrastructure
The internet comprises an enormous amount of physical infrastructure.
-
Most of it is wired, not wireless. Wireless is mainly used for the first hop.
-
Most of it is fiber (glass), not copper. Signals degrade quickly in copper but travel faster and with less attenuation in glass 1. Copper is only used for the last 100 meters.
-
The internet wouldn’t exist without fiber optic cable. It’s one of the wonders of the modern world. It’s not just glass, it’s really clear glass.
An Internet Journey
If you want to learn more, you can join me as we follow a cable from my former office to the edge of our campus network.
-
Next hop to the network closet on my floor. Here copper gives way to fiber.
-
My last hop on campus. At this point all of the campus network traffic leaves on only a few slim fiber optic cable.
Internet As Wireless Infrastructure
In recent years we’ve also built out a huge amount of wireless internet infrastructure.
-
Short range wireless is dominated by WiFi and what you use when you’re on campus, at home, or at a coffee shop
-
Medium-range wireless is used to provide connectivity to mobile devices like smartphones over longer distances. You usually buy this from a cellular provider like Verizon or Sprint.
Internet As Connectivity
The result is that by connecting a computer to the internet, you are now connected to 4 billion other computers.
-
Many times the first connection is wireless
-
But after that point there is literally a wire that you can follow from your computer to the other computer
But How Do Internet-Connected Devices Communicate?
Internet As Agreement
A communication protocol is a system of rules that allow two or more entities of a communications system to transmit information.
The Internet Protocol (IP)
The Internet Protocol (IP) consists of a series of agreements that allow internet-connected devices to communicate.
-
What do we call each other? IP specifies the format of internet protocol addresses, also called IP addresses.
-
Here’s one:
192.17.96.8
(IPv4) -
Here’s a new one:
2607:f8b0:4009:807::2004
(IPv6)
-
-
How are our message structured? IP specifies a format for each message (or datagram) exchanged across the internet.
IP Datagram Format
The Miraculous Internet
The core internet protocols were invented by a bunch of graduate students, including Vint Cerf and Bob Kahn. They changed the world.
Vint Cert has said "we kept wondering when the adults were going to show up."
So We Can Talk, But About What?
Internet Protocol Stack
So The Web Is Not The Internet
The web is just one of many services running over the internet.
What is the World Wide Web?
-
A protocol: the Hypertext Transfer Protocol (HTTP)
-
A markup language: the Hypertext Markup Language (HTML)
-
A styling language: Cascading Style Sheets (CSS)
-
A programming language: JavaScript
HTTP: GET
Request
HTTP defines how web browsers request (GET
) content:
When you type
http://cs125-illinois.github.io/lecture-webapis-examples/simple.html
into your browser, it sends a message to cs125-illinois.github.io
that looks
like this:
GET /lecture-webapis-examples/simple.html HTTP/1.1
Host: cs125-illinois.github.io
GET
Parameters
You can send some data to the server in a GET
request using query
parameters.
-
These follow the path and an
?
sign in the URL -
Each takes the form
key=value
-
Key-value pairs are separated by
&
delimiters -
Here’s an example:
search?safe=off&source=hp&q=cs125
:-
safe=off
-
source=hp
-
q=cs125
-
HTTP: GET
Response
If the request succeeds, the server responds with something that looks like this:
HTTP/1.1 200 OK
Date: Sun, 08 Apr 2018 08:56:53 GMT
Last-Modified: Sat, 20 Nov 2014 07:16:26 GMT
Content-Length: 44
Content-Type: text/html
<html>
<body>
...
HTTP: POST
Request
HTTP also defines how web browsers submit information (POST
):
When you submit the form on
http://cs125-illinois.github.io/lecture-webapis-examples/form.html
,
it sends a message to cs125-illinois.github.io
that looks like this:
POST /lecture-webapis-examples/simple.html HTTP/1.1
Host: cs125-illinois.github.io
text=word
Note that this fails on github.io
because it only serves static pages and
doesn’t deal with data provided by users.
HTTP: GET
and POST
HTTP defines many other types of requests, but GET
and POST
are by far the
most common.
-
Every time you load a web page it starts with a
GET
, and usually that’s followed by many otherGET
requests to fetch others parts of the page: style sheets, images, JavaScript code. -
Every time you submit a form it uses a
POST
to send data to the server, at which point your Facebook comment is recorded, or your credit card is charged and an package starts its way toward your house
HTTP: GET
v POST
The HTTP protocol specifies different semantics for GET
and POST
:
-
GET
should not change anything about the world, just return a document -
POST
should change something about the world—create a new account, pay your bill, purchase something, send a message, etc. -
As a result it is safe to repeat a
GET
but potentially problematic to repeat aPOST
: hence the "Do not click back" and "Do not submit this form twice" kind of warnings.
Announcements
-
Enjoy break! Get some rest. Start planning your final project.
-
The MP5 deadline is today—office hours until 5PM.
-
I have office hours MWF from 10AM–12PM in Siebel 2227. Please stop by!
-
Remember to provide feedback on the course using the anonymous feedback form.
-
I’ve started to respond to existing feedback on the forum.