- What is an HTTP request?
- What is an HTTP Response?
- What is the HTTP standard?
- What types of HTTP requests are there?
- What is the difference between a Get and a Post?
- What is HTTP Header?
- How do I make an HTTP request in vanilla JS?
- What do the HTTP response codes tell me 1xx, 2xx, 3xx, 4xx, 5xx?
HTTP is the backbone of the web, for both human users and other programs (APIs)
- What is the HTTP standard?
- HTTP Request
- HTTP Response
- HTTP Header
- HTTP Status Codes
- HTTP Crash Course - first 17 minutes are all that matter but feel free to watch the whole thing as it covers Postman
- Routing HTTP requests
- Servers, Requests, and Responses
- Watch the crash course video above
- Ask the SEAM for a paper copy of the HTTP Zine by Julia (b0rk)
- Work through the rest of the practice
Node has a library as http.request
. It is called http.server
.
- For a prebuilt version
npm install -g http-server
http-server
- This will start a web server that will serve files in the current directory
- Run it in one of your project folders, such as your portfolio
- It will announce that it started a server on two sockets. We'll cover that again in Networking
- Open the location in your browser:
http://127.0.0.1:8080
Tutorial to do it yourself:
Now make some requests against it with your browser and also curl
. Try logging all the data made available to you in the request object, such as headers.
Instead of using a browser, let's see what's happening underneath by using nc
, short for netcat, a built-in tool on Mac which allows us to do lots of interesting low-level network tasks.
nc <server> <port>
(note: it's not a colon like in a URL)nc www.google.com 80
- It will connect and inform you of the escape character and then wait for input
- type
GET /
then enter twice. This is the smallest valid HTTP request - A Google web server will spit out the Google home page
- Why do you have hit enter twice?
- Why does the 80 port not show up in the browser?
User Agent is a voluntary header that browsers send identifying themselves.
Extend your Node web server above to console.log which browser the user is uses. Try out mobile browsers to see how they look different.
Hint: Add this line to your server-side Node.js code console.log(req.headers['user-agent'])
If you're curious what each required piece is, check out this simplified HTTP specification. The complete spec is huge and uses a formal mathematical language if you want to go down a rabbit hole.