Computers and the Internet · Clients and servers
What is a request?
A request is a structured message a client sends to a server, saying what it wants, where, and with what extra details.
- Time12 min
- LevelBeginner
- Pictures10 diagrams
- Check5 questions
Computers and the Internet · Clients and servers
A request is a structured message a client sends to a server, saying what it wants, where, and with what extra details.
Your goal: Describe what a request is, name its four main parts (method, path, headers, body), and read a simple HTTP request.
Thousands of companies build apps, browsers and TVs; thousands more build servers. They never met, yet must understand every message exactly.
Everyday view
A waiter never shouts "something tasty for table 4" into the kitchen; they write an order slip with a fixed layout. A request is the same kind of slip, sent from a client to a server.
An order slip and a request do the same job
Why it exists
Browsers, web servers, phone apps, smart TVs and payment terminals are built by thousands of different companies, yet they must talk to each other without ever having met. That only works if every request follows one public, agreed format.
Many makers, one agreed format
How it works
Every HTTP request is built from the same four parts: a method (what to do), a path (which thing), headers (extra details) and sometimes a body (the data you send).
The four parts of a request that posts a comment
See it
A request is read top to bottom: first the request line (method, path and version), then the headers, then an empty line, and finally the body, if there is one.
POST /recipes/pancakes/comments HTTP/1.1: the method, the path and the protocol version.Host, Content-Type, Content-Length and others: labeled extra details.{"author":"sam","text":"Add lemon."}: the data being sent. Often absent./recipes/pancakes/comments) set by the page's code.In the real world
Opening one news article sends far more requests than you might think: one for the page's HTML, then one for every stylesheet, script, font and image that HTML mentions. A single page commonly needs dozens of requests, and apps send them in the background too.
Requests you send without noticing
Trade-offs
The strict format lets any client talk to any server, and lets tools like caches and security filters inspect requests without knowing the application. Its biggest catch is that anything a request passes through can read it, unless the connection is encrypted.
Who can read a request on its way
Knowledge check
5 questions. Pass with 70% to complete the lesson. Answers are explained after you submit.
Explain it yourself
Revision card
Key points
Recall — answer in your head first
Name the four parts of an HTTP request and say what each one is for.
Why does a request for a web page usually have no body, while a login request does?
Why must requests follow a strict format?