Internet Architecture basics
How the web technologies work (free live class )
1/10/2014
Want to learn more?
How does the Internet Work?

Requests
The browser (aka client) connects to the internet and makes a request to a server (another computer on the internet)
Requests are made by visiting a URL (www.google.com)
Requests ask for a resource (for now, think of it as a file)
Hey Google computer, I would like a file called
'Search Results for Cats' within your file system
Request Components
The URL is broken down into component parts parts
(protocol, hostname, & path)
hostname --> www.enginehere.com
The hostname is associated with a numerical address (IP )
That address points to where the underlying server (computer) is connected to the network. During the request, that address is looked up based on the hostname
Request Components: Continued
The path refers to the resource (think of it as a file for now)
which you are asking for on the server
You've encountered paths on your own computer
/Desktop/Downloads/self.png
The path for this particular web page is
/stream/428/internet-architecture-basics/
Response
So far, we have assumed that the server is handing us back a file based on the path of our request
With old static sites, that was often the case
You would see things like
www.ezmoney-now/index.html
Nowadays, the server runs a program (in Python, Ruby, Javascript ,etc) which returns a dynamic block of text as a response to your request.
The Server

The server program returns the resource at the given path as a response to the browser
The response is just a string of text (HTML, images, video, etc)
The browser renders this content on the screen
User input via web Forms
Website generally respond to user input
What is your username? Who to follow?
When websites want user input, they typically use forms
Forms submit data to servers via requests (hit urls with data)
GET vs. POST
Form Example

Get vs. Post Requests
The method of the request (GET vs. POST) provides the server with an extra bit of data for determining how to respond
Functionally very similar (both are requests to a given url with optional extra associated data)
Some structural differences though
GET Method
Extra data is communicated in the url itself
www.mailchimp.com/?your_login=ben&your_password=demo
Everything after the question mark (?)
is extra data in key/value pairs separated by ampersands (&)
your_login=ben
your_password=demo
Why is this useful?
POST METHOD
Data is not sent via the url
Instead, it is sent through an extra request body
See Canvas Area (picture icon above)
Which Method to use
POST when you change something through your request
For example, if you follow someone on Twitter
you are making a change (data updates)
If you do a search on AirBnB, nothing really changes (mostly).
You can find the same apartments if you search 5 times
Forms on the Web Server
A program on the server
(could be written in many different languages)
receives this requests, processes it, and returns a response
Click "login_server" in the IDE for simple example in Python
Web Sessions
HTTP is stateless, meaning each request is independent
To keep track of users (i.e. facebook), we need to preserve state
We use a combination of Cookies and databases
Cookies are strings sent by servers to browsers (and vice versa) on each request and can be used to identify a user
API
Rather than making requests to a server through a browser
you can connect to a server through a programmatic client
Still make GET/POST requests
but do it through code
Build your own Website
# from the command line pip install the web server library
sudo pip install lpthw.web
import web urls = ( '/', 'index' ) app = web.application(urls, globals()) def index(request):
greeting = "Hello World" return greeting if __name__ == "__main__": app.run()
When you run this script, it will start a server at the address:
http://localhost:8080 (same as http://127.0.0.1:8080)
Next Steps (Deploy to the Cloud)
The final exercises tell you to set up Nginx or Apache
These are classic web servers that you can deploy to machines on the cloud (you've just run local servers so far)
These servers, in turn, run Django Ruby on Rails, Node.js, or other web frameworks
If you are adventurous, you can set this up on AWS
Or you can just use Heroku
Internet Architecture Basics
By benjaminplesser
Internet Architecture Basics
- 1,939