Some examples for today are available here:
Feel free to fork!
Given a line of text, write a function that searches for all occurrences of a given word.
What’s Our Algorithm?
> Click or hit Control-Enter to run the code above
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.
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
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 a new one:
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?
HTTP defines how web browsers request (
When you type
into your browser, it sends a message to
cs125-illinois.github.io that looks
GET /lecture-webapis-examples/simple.html HTTP/1.1 Host: cs125-illinois.github.io
You can send some data to the server in a
GET request using query
These follow the path and an
?sign in the URL
Each takes the form
Key-value pairs are separated by
Here’s an example:
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 also defines how web browsers submit information (
When you submit the form on
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 defines many other types of requests, but
POST are by far the
Every time you load a web page it starts with a
GET, and usually that’s followed by many other
Every time you submit a form it uses a
POSTto 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
The HTTP protocol specifies different semantics for
GETshould not change anything about the world, just return a document
POSTshould 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
GETbut potentially problematic to repeat a
POST: hence the "Do not click back" and "Do not submit this form twice" kind of warnings.