CS1999
Intense intro to webservers
Foundation CompSci project
You all know some of this already
what a webserver does
the Hypertext Transfer Protocol
how Flask fits in
1
webserver
request → response
example page load
an HTML page contains other resources
resulting in multiple requests
Requests and responses
headers — meta information
payload — what they are actually sending
that's it
OK, it's more complicated than that
DNS and virtual servers
caching, sessions, storage
security, authentication, abuse
what if page is not there?
requests can't always be served
the servers says no
2
HTTP
All computers on the web agree
it's a protocol
the Hypertext Transfer Protocol
of interest to you: status codes and methods
Request
do what (the method)
to what (the URL)
You know how this works?
No More Kings
Sweep the Leg
So here's what you put in your request
- can I get...
- Dominoes
- your home address
- what you want (pizza)
- veggie royale
- extra jalapeños
So here's what you put in your request
- what action
- which supplier
- the return address
- what kind of thing you wanted
- what it was called
- any data to go with that
So here's what you put in your request
- method ("verb")
- authority (host & port)
- your IP address
- accept media types
- path
- arguments/data
All you do with pizza is GET
Clients can choose *methods*
GET is common... but there are others.
Let's have a look!
METHODS
HTTP specifies a METHOD indicating the nature of the request
(unofficially, "the verb"):
HTTP method to
retrieve data
This is the one you probably use most.
HTTP method to
retrieve no data
GET without the body payload.
You'd do this to see if the pizza delivery network works
before investing in an order.
HTTP method to
send data to process
This is the one you've probably used every time you pressed SUBMIT on a form.
You don't do this unless you send ingredients to Dominoes to put on your pizza.
HTTP method to
send data to store
"Hello Dominoes? Could you look after this pizza for me? Ta."
HTTP method to
delete
"Hello Dominoes? Cancel that I've got a burger instead."
HTTP method to
send data for modifying
Updating pizza... I think this analogy has run its course...
Browser URL bar
Right, knowing that, you can see the first half of what a browser does:
it creates the request
The URL break-down
SCHEME |
:// |
AUTHORITY |
/ |
PATH |
? |
QUERY |
# |
FRAGMENT |
protocol |
host & port |
path |
arguments / data |
location in page |
Status codes
MDN status codes
Status codes
cat status codes
3
Flask
Flask
Python program that listens for requests
and sends back responses
Example
a simple example
Want a bigger example?
your buggy editor!