Skills / Back-end development and APIs / How the web talks: clients, servers and HTTP

Back-end development and APIs, lesson 1 of 8

How the web talks: clients, servers and HTTP

When you open an app, your phone or browser (the client) sends a message to a computer somewhere else (the server). The server does some work, perhaps reads a database, and sends a reply. That conversation follows a set of rules called HTTP.

An HTTP request has:

  • A method saying what you want to do: GET (read), POST (create), PUT or PATCH (update), DELETE (remove)
  • A path saying what it is about, such as /orders/42
  • Headers with extra details, such as who you are signed in as
  • Sometimes a body with data, for example the new order as JSON

An HTTP response has:

  • A status code: 200 OK, 201 created, 400 bad request (the client sent something wrong), 401 not signed in, 403 signed in but not allowed, 404 not found, 500 the server failed
  • Headers, and usually a body, very often in JSON, a simple text format for data: {"id": 42, "status": "shipped"}

The first digit tells you who to look at when something breaks: 4xx means the request was wrong, 5xx means the server has a problem.

The back end is everything on the server side: receiving requests, checking them, applying the business rules, talking to the database and sending back the right response. The user never sees it, but every login, payment and search depends on it.

You can watch this conversation yourself: open your browser's developer tools, go to the Network tab and reload any page.

Try it: Open the Network tab in your browser's developer tools and reload a site you use. Find one request, then note its method, its path and its status code.

Check yourself

1. Which HTTP method is used to read data?

2. A request returns status 404. What does that mean?

3. Who is usually at fault when a response is in the 5xx range?