Skip to content

HTTP Requests, Responses and Status Codes Explained with Real Traffic

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

An HTTP exchange is two short text messages. The client says what it wants: a method, a path and some headers. The server answers with a status code, its own headers and usually a body. Everything else, the browser, the framework, the CDN, builds on those two messages. In this lesson you read a real exchange that curl captured with JSONPlaceholder, a public test API, then see eleven status codes come back from a real server, follow two redirects on needmytools.com and meet the difference between a server error and a network error. Live examples send the same kind of requests from your own browser.

Quick answer

An HTTP request has a method (GET reads, POST creates, PUT replaces, PATCH updates part, DELETE removes), a path, headers and an optional body. The response starts with a status code: 2xx means success (200 OK, 201 Created, 204 No Content), 3xx means go elsewhere (301, 302, 307, 308), 4xx means the client sent something wrong (400, 401, 403, 404, 429), and 5xx means the server failed (500, 503). In JavaScript, fetch resolves for every status, so check res.ok.

35 min read and practice · Content checked on 29 November 2026

In this lesson you will

  • Read the request line, status line, headers and body of a real exchange
  • Pick the right method for reading, creating, updating and deleting
  • Explain the five status code families and the common codes in each
  • Tell an HTTP error from a network error in fetch

A real request and response, line by line

The lines starting with > are what curl sent. The first is the request line: the method GET, the path /todos/1 and the protocol HTTP/2. Then come request headers. Host names the website, because one server often hosts many sites; User-Agent says which program is asking; and Accept: */* says any format is fine. A GET request has no body, so the blank line ends it.

The lines starting with < are the response. HTTP/2 200 is the status line. The headers describe the body: content-type says it is JSON in UTF-8, content-length: 83 says it is 83 bytes, and cache-control and etag control caching, which the next lesson covers. After a blank line comes the body, the to-do item as JSON. Notice that the server also announced x-powered-by: Express, the same header you saw in the Node.js course.

HTTP is stateless: each request carries everything the server needs, and the server does not remember the previous one by itself. That is why the same headers appear on every request, and why logins need cookies or tokens, which come later in this course. It is also what lets one API serve millions of clients from many machines behind a load balancer.

Example: curl -v https://jsonplaceholder.typicode.com/todos/1
Real output: request and response headers (proxy and TLS lines removed)
> GET /todos/1 HTTP/2
> Host: jsonplaceholder.typicode.com
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/2 200 
< date: Sun, 29 Nov 2026 09:01:18 GMT
< content-type: application/json; charset=utf-8
< content-length: 83
< access-control-allow-credentials: true
< cache-control: max-age=43200
< etag: W/"53-hfEnumeNh6YirfjyjaujcOPPT+s"
< expires: -1
< pragma: no-cache
< vary: Origin, Accept-Encoding
< x-content-type-options: nosniff
< x-powered-by: Express
Real output: the body that followed
{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}

We removed the lines our network proxy added (a CONNECT request), the TLS handshake lines and some Cloudflare headers such as report-to and cf-ray. Everything shown is exactly as received. The title is placeholder Latin text that the test API uses on purpose.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What is the difference between 301 and 302 redirects?

301 is permanent: browsers may cache it and search engines move rankings to the new address. 302 is temporary, so the old address stays the main one. For permanent moves that must keep a POST as POST, use 308; for temporary ones, 307.

Why do I get 401 when I am sure my password is right?

For APIs, 401 usually means the token or key is missing, expired or sent in the wrong header, not that the password is wrong. Check the exact header name the API expects, such as Authorization: Bearer ..., and whether the token has expired.

What does error 429 Too Many Requests mean?

You hit the rate limit: too many requests in a short time. Slow down, cache results you already have, and wait as long as the Retry-After header says before trying again. Many free APIs limit requests per minute or per day.

How can I see the HTTP requests a website makes?

Open the browser developer tools with F12 and choose the Network tab, then reload the page. Each row is one request; click it to see the method, status, request and response headers and the body, the same parts you read in this lesson.

Is HTTPS a different protocol from HTTP?

HTTPS is HTTP sent inside an encrypted TLS connection. The methods, status codes and headers are identical; TLS stops others on the network from reading or changing them. Every public site and API should use HTTPS.

Sources

Facts in this lesson were checked against these official pages on 29 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.