Request and response
After today, you can read a URL piece by piece, describe what a browser sends and gets back, and tell a 404 from a 500.
Dip your toes 1 min
Every time you open a web page, your browser and a server hold a short, structured conversation. The browser sends a request, a message asking for one thing, like Wikipedia’s article on bridges. The server sends back a response: the page itself, plus a three-digit status code saying how it went. A 200 means it worked. A 404 means nothing lives at that address, often because of an old link. A 500 means something broke on the server. Those codes decide which error screen a user sees. A server failure calls for an apology and a way to try again. A missing article is different: Wikipedia’s page offers to search for it instead.
The full lesson 10 min
Why this exists
Type “Bridge” into Wikipedia’s search box and press Enter. Within a second, an article about bridges appears. Your browser was made by one company. Wikipedia’s servers are run by the Wikimedia Foundation, a nonprofit. The two programs have never met, yet they hold a precise conversation in a fraction of a second.
That works because both sides follow the same rules. Without shared rules, every website would need its own browser, and every browser would need custom code for every site.
The web settled this early with three agreements. One is a way to name anything on the web. One is a directory that turns those names into places. And one is a format for asking and answering.
Day 6 described the frontend and the backend trading requests and responses. Today is about what those messages look like on the web, and how much they tell you when something goes wrong. Most of it is readable once you know where to look. Engineers read it every day, and so can you.
What it is
The first agreement is the URL (Uniform Resource Locator), the full address of one thing on the web. Every page, image, and file has one. Except for the host, which reads the other way, a URL reads left to right, from the most general part to the most specific. Here’s the address of the edit history of Wikipedia’s article on bridges, split into its parts.
The protocol says which rules to use. The host names the server, here the English edition of Wikipedia. The path points to one page on that server.
The query, everything after the question mark, adds options as name and value pairs. Here it asks for the page’s history instead of the article. A URL can also end in a fragment, a part after a # sign that jumps to a heading within the page.
The second agreement is DNS, the Domain Name System. Computers on the internet find each other by numeric addresses, not names. DNS is the directory that turns a name like en.wikipedia.org into one of those numbers. Before your browser can ask Wikipedia for anything, it asks a DNS resolver, a server whose job is looking up names. The answer usually gets saved for a while, so the lookup doesn’t repeat on every click.
When DNS fails, the browser never reaches the server at all. You see the browser’s own error page, not the site’s, because there was no site to answer. That’s a useful clue in a bug report. A page with the product’s branding means the server answered. A plain browser message means the request never got that far.
The third agreement is HTTP (HyperText Transfer Protocol), the shared rules for formatting requests and responses on the web. An HTTP request starts with a method, a verb that says what you want. GET means “send me this,” and it’s what your browser uses to load a page. POST means “here’s something for you,” like a form you submit or an edit you save. After the method comes the path, then a set of headers.
A header is a labeled line of extra information. A request might carry Accept-Language: en, which says the reader prefers English. A response might carry Content-Type: text/html, which says the body is a web page rather than an image. Headers also carry the details that keep you signed in, which is why engineers check them first when a login acts strangely. Some requests also carry a body, like the text of an edit.
The response comes back in the same shape, with one addition at the top. A status code is a three-digit number that says how the request went.
A 200 means it worked. A 404 means the server found nothing at that path. A 500 means something broke on the server while it tried to answer. After the status come the response’s headers, then its body: the HTML, the image, or the data that was asked for.
The “s” in https stands for secure. The browser and server scramble the whole conversation so nobody in between can read or change it. Almost every site uses https now, and browsers warn you when one doesn’t. If you type the old http address for Wikipedia, the browser gets sent to the https version.
Put together, one click on a Wikipedia link uses all three agreements. The browser reads the URL, asks DNS for the host’s address, and sends a GET for the path. Then it reads the HTML in the response and finds the images and styles it mentions. Each of those takes its own trip, so one article can mean dozens of requests.
How it shows up in your work
Every request and response is visible to you while you work. Open the developer tools in your browser and choose the Network tab, then reload the page. Each row is one request, with its status code, its type, and how long it took. Click a row and you’ll see both halves of the conversation, laid out much like this.
This turns a vague bug report into a precise one. “The page didn’t load” could mean almost anything. “The search request came back with a 500” tells an engineer where to start.
You don’t need to understand every header. Find the row that failed, note its status code and its path, and put both in the ticket. Failed requests usually show up in red, so they’re easy to spot in a long list.
URLs are design decisions too. A URL that holds the state of a screen, like a search term or a set of filters, can be bookmarked, shared, and reopened. Wikipedia’s search results live at an address with the search term in the query, so you can send someone a link to them. When a design adds filters, tabs, or steps, ask whether they change the URL. If they don’t, the back button and shared links may not do what users expect.
Paths are worth designing as well. Wikipedia’s article paths are the article titles, like /wiki/Golden_Gate_Bridge, so people can read a link before they click it.
Error states are the third place. A good design has a different screen for each kind of failure, because each one needs a different next step. A missing page needs a way to find the right one. A server failure needs reassurance and a way to try again.
Which screens a product needs depends on which status codes its requests can return. Only an engineer can answer that for your product.
The one thing people get wrong
An error page appears, and someone says “the server broke.” Surely something on the company’s side failed. In fact, status codes come in families, and only one family means the server broke. The first digit tells you which family you’re in, and whose problem it is.
A 2xx code means success. A 3xx code is a redirect: the thing moved, and the response says where, so the browser follows without the user noticing.
A 4xx code means the request was the problem. A 404 means nothing lives at that path, often because of a mistyped or outdated link. A 401 or 403 means the server won’t give you what you asked for. You’re either not signed in or not allowed.
Only a 5xx code means the server failed. A 500 means something broke while it built the answer. A 503 means it’s overloaded or down for maintenance and can’t answer right now. These are the errors that wake an engineer at night. A wave of 404s, on the other hand, usually points to a broken link somewhere in the product, which a designer can help find.
The difference changes what the user should see. Wikipedia’s answer to a missing article is a 404, but its page doesn’t stop at an apology. It says Wikipedia does not have an article with that exact name, then offers to search for it instead. That’s a designed 404: it treats the error as a wrong turn and offers a way forward.
A 500 page can’t do that, because the problem isn’t the user’s request. The honest message there admits the problem is on the company’s side and invites the user to try again soon.
One more catch: a status code is a promise, not a guarantee. Some systems answer 200 and tuck an error message inside the body. Others answer 404 when the real cause is a permission check. So the code tells you where to start looking, and the body tells you what happened. When a screen shows the wrong error, check both.
Ask an engineer this
“When this screen shows an error, which status codes can actually come back, and what should the user see for each one?”
Ask this while you’re designing error states for a feature, before anyone builds them. Expect a short list: a 404 when an item was deleted, a 403 when someone lacks access, a 5xx when a service is down. Mark which codes need different words or actions on screen, and which ones the engineer says will never happen. For each one, find out what the screen shows today. By the end, you’ll know how many error states you’re designing, and which ones currently fall back to a blank page.
Terms from today
- URL
- Uniform Resource Locator, the full address of one thing on the web, from the protocol and the server’s name down to the specific page.
- HTTP
- HyperText Transfer Protocol, the shared rules browsers and servers follow to format requests and responses on the web.
- Status code
- A three-digit number at the start of every HTTP response that says how the request went, like 200 for success or 404 for not found.
- Header
- A labeled line of extra information sent with a request or response, such as the type of content or the reader’s preferred language.
- DNS
- The Domain Name System, the internet’s directory, which turns a name like en.wikipedia.org into the numeric address of a server.