]> code.delx.au - learning/blob - lesson1_HTTP.md
Learning HTTP
[learning] / lesson1_HTTP.md
1 # Lesson 1 HTTP
2
3 ## References:
4 - https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
5 - https://www.rfc-editor.org/rfc/rfc2616
6 - https://curl.se/docs/manpage.html
7
8 ## Overview
9
10 In the 1991 HTTP was created. Web browsers used HTTP to fetch static HTML, text and images from web servers. These static files were sitting in a directory on a server. The only way to change the website was to update these files.
11
12 You could type a URL like `http://acme.com/products.html` into a graphical web browser, the browser would then speak HTTP to the `acme.com` server to fetch the `/products.html` file. The user may then click a `<a href="http://contoso.net/about.html">` to cause the browser to visit a different site, speaking HTTP to the `contoso.net` server to fetch the `/about.html` file.
13
14 ## Learning objective
15
16 The goal is to learn about HTTP, specifically what it does and what it looks like.
17 - What is an HTTP method?
18 - What is an HTTP status code?
19 - Identify the components of a URL, server, path.
20 - How does an HTTP server use the server and path from the URL?
21
22 ## Exercises
23
24 ### Run a simple web server using Python
25 - Make new directory with some text or html files, at least two. Eg demo.html and hello.txt.
26 - Open terminal in that directory. Right click, open in terminal.
27 - Start the web server: `python -mhttp.server`
28 - Keep this terminal window open for later.
29
30 ### Access the web server with a browser like Firefox
31 - Open web browser and visit: http://localhost:8000
32 - See what is happening in the web server terminal window.
33 - You can click on the files to view them.
34 - The browser is acting as an HTTP client to view the files being served by the Python HTTP server.
35
36 ### Access the web server with a command line client, curl
37 - Open a new terminal window in addition to the Python web server one.
38 - Run `curl http://localhost:8000` to see the directory index generated by the web server.
39 - Run `curl http://localhost:8000/demo.html` to see a file you created in the web server directory.
40 - Try variations of this like: `/hello.txt`, or `/missing.txt`
41 - You can also try this on other web servers, like `https://www.google.com`
42 - Try in verbose mode to see the raw HTTP: `curl -v http://localhost:8000`
43
44 ### Access the web server by typing raw HTTP
45 - Run command `nc localhost 8000`
46 - Enter `GET / HTTP/1.0`, then press return twice
47 - Try with `GET /hello.txt` or other variations to see how the server responds.
48
49 HTTP is just text! When you click a link, all that Firefox does is send this text to the server and display the result on the screen.