Post

Web Development Fundamentals — Part 7: HTTP — How the Web Communicates

Web Development Fundamentals — Part 7: HTTP — How the Web Communicates

Series Overview

This is an 8-part series covering the core technologies of web development:

  1. HTML — The Structure of the Web — Elements, attributes, block vs inline, and document structure
  2. CSS — Styling the Web — Selectors, properties, the box model, and layout basics
  3. JavaScript — Adding Interactivity — Variables, data types, functions, arrays, and control flow
  4. The DOM — Connecting JavaScript to HTML — Selecting elements, changing styles, and modifying attributes
  5. jQuery — Write Less, Do More — Selectors, events, and DOM manipulation with jQuery
  6. Bootstrap — Responsive Layouts Made Easy — Grid system, responsive breakpoints, and rapid prototyping
  7. HTTP — How the Web Communicates (this article) — Requests, responses, methods, and status codes
  8. React — Building Modern User Interfaces — Components, JSX, props, state, hooks, and thinking in React

What Is HTTP?

HTTP (HyperText Transfer Protocol) is a client-server protocol. Requests are sent by one entity — the user-agent (usually a web browser, but it can be anything, like a search engine crawler or a mobile app) — to a server, which handles the request and provides a response.

Every time you load a web page, your browser is making HTTP requests and receiving HTTP responses. Understanding this protocol is essential for web development, whether you’re building frontend applications that consume APIs or backend services that serve them.

The Request

An HTTP request consists of:

  1. HTTP method — A verb like GET or POST that defines what the client wants to do
  2. Path — The URL of the resource (e.g., /api/users)
  3. HTTP version — e.g., HTTP/1.1 or HTTP/2
  4. Headers — Optional metadata (e.g., Content-Type, Authorization)
  5. Body — Optional data sent with the request (used with POST, PUT, etc.)

Example raw request:

1
2
3
GET /index.html HTTP/1.1
Host: www.example.com
Accept: text/html

HTTP Methods

HTTP methods indicate the desired action to be performed on a resource. Each method has different semantics, but they can be grouped by properties like safety (read-only) and idempotency (same result regardless of how many times called).

The Five Core Methods

MethodPurposeSafeIdempotent
GETRetrieve a resourceYesYes
POSTCreate a resource or submit dataNoNo
PUTReplace a resource entirelyNoYes
DELETERemove a resourceNoYes
HEADSame as GET but without the response bodyYesYes

GET — Requests a representation of a resource. Should only retrieve data, never modify it.

POST — Submits data to a resource, often causing a change in state or side effects on the server (creating a record, submitting a form, triggering a process).

PUT — Replaces the entire target resource with the request payload. If you send a PUT to /users/1, you’re saying “here is the complete new state of user 1.”

DELETE — Removes the specified resource.

HEAD — Identical to GET but returns only headers, no body. Useful for checking if a resource exists or reading metadata without downloading content.

The Response

An HTTP response consists of:

  1. HTTP version — e.g., HTTP/1.1
  2. Status code — A three-digit number indicating the result
  3. Status message — A short description (e.g., “OK”, “Not Found”)
  4. Headers — Metadata about the response
  5. Body (optional) — The content of the response (HTML, JSON, an image, etc.)

Example raw response:

1
2
3
4
5
6
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234

<!DOCTYPE html>
<html>...

Status Codes

Status codes tell the client what happened with their request. They’re grouped into five categories by their first digit.

1xx — Informational

The server received the request and is continuing to process it.

CodeMessageMeaning
100ContinueInitial part of request received, client should continue
101Switching ProtocolsServer is changing protocols as requested

2xx — Success

The request was successfully received, understood, and accepted.

CodeMessageMeaning
200OKStandard success response
201CreatedNew resource was created (typically after POST)
202AcceptedRequest accepted but processing not complete
204No ContentSuccess but no content to return (common for DELETE)

3xx — Redirection

The client needs to take additional action to complete the request.

CodeMessageMeaning
301Moved PermanentlyResource has a new permanent URL — update your bookmarks
302FoundResource temporarily at a different URL
304Not ModifiedCached version is still valid, no need to re-download
307Temporary RedirectLike 302, but the HTTP method must not change
308Permanent RedirectLike 301, but the HTTP method must not change

4xx — Client Error

The request contains an error on the client’s side.

CodeMessageMeaning
400Bad RequestMalformed syntax or invalid parameters
401UnauthorizedAuthentication is required (login needed)
403ForbiddenAuthenticated but not authorized (no permission)
404Not FoundThe resource does not exist
405Method Not AllowedThe HTTP method is not supported for this resource
408Request TimeoutThe server timed out waiting for the request
409ConflictRequest conflicts with the current state of the resource
410GoneResource was intentionally removed and won’t be back
413Request Entity Too LargeThe request body exceeds the server’s size limit
415Unsupported Media TypeThe request format is not supported

5xx — Server Error

The server failed to fulfil a valid request.

CodeMessageMeaning
500Internal Server ErrorGeneric server-side error
501Not ImplementedThe server doesn’t support the functionality required
502Bad GatewayThe server (acting as gateway/proxy) got an invalid response from upstream
503Service UnavailableServer is overloaded or down for maintenance (usually temporary)
504Gateway TimeoutThe gateway/proxy didn’t get a timely response from upstream

Status Codes You’ll See Most Often

In day-to-day web development, these are the ones that matter most:

  • 200 — Everything worked
  • 201 — Resource created (after a POST)
  • 204 — Success, no content to return (after a DELETE)
  • 301/302 — Redirects
  • 400 — Bad input from the client
  • 401 — Not logged in
  • 403 — Logged in but not allowed
  • 404 — Resource not found
  • 500 — Server error (check the logs)
  • 503 — Service temporarily down

What’s Next?

With the fundamentals in place — HTML, CSS, JavaScript, the DOM, and HTTP — you’re ready to build modern user interfaces. In Part 8, we’ll learn React, the most popular JavaScript library for building component-based, declarative UIs.

References

This post is licensed under CC BY 4.0 by the author.