How the Internet Works
HTTP Requests and Responses
In this lesson you will
- Describe a request and a response
- Recognise common methods and status codes
- Explain what happens when you load a page
Introduction
Once your browser knows a server's address, it has to ask for the page in a way the server understands. The language for this is HTTP, the HyperText Transfer Protocol.
The simple explanation
HTTP is a conversation. The client sends a request, and the server sends back a response.
It is like ordering at a counter. You say what you want, and you get what you asked for, or an explanation of why not.
A request
A request has:
- A method that says what you want to do
- A path that says which thing
- Headers with extra information, such as your browser type
- Sometimes a body, such as a submitted form
Common methods:
| Method | Meaning |
|---|---|
| GET | Fetch something |
| POST | Send new data, such as a form |
| PUT | Replace something |
| DELETE | Remove something |
A simple request looks like this:
GET /about HTTP/1.1
Host: example.comA response
The server replies with a status code, headers and usually a body such as the HTML of the page.
HTTP/1.1 200 OK
Content-Type: text/htmlStatus codes come in groups:
- 2xx success, such as
200 OK - 3xx redirect, such as
301 Moved Permanently - 4xx the client made a mistake, such as
404 Not Found - 5xx the server had a problem, such as
500 Internal Server Error
Quick quiz
Which status code means the page you asked for was not found?
What happens when a page loads
- You enter a web address.
- DNS finds the server's IP address.
- Your browser connects and sends a GET request.
- The server replies with HTML.
- The HTML points to CSS, images and scripts, so the browser makes more requests for each.
- The browser puts it all together and shows the page.
You can watch these requests in your browser's developer tools, under the Network tab.
Try it yourself
Open any website, open the developer tools (usually F12), choose the Network tab and reload. Find the first request and look at its status code. How many requests did the page make?
Summary
- HTTP is a request and response conversation between client and server.
- Methods such as GET and POST say what to do, and status codes say how it went.
- One page load usually makes many requests.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading