HTTP Fundamentals

Before discussing advanced API architectures like GraphQL or REST, you must deeply understand the underlying transport layer: HTTP (Hypertext Transfer Protocol).

Every time a frontend application (like a React web app or an iOS mobile app) wants data from a backend server, it constructs and sends an HTTP Request.

[!TIP] ELI5: The Mail System Think of an HTTP Request as sending a physical letter through the mail.

  • The URL: The destination address on the envelope.
  • The Method (Verb): A sticker on the envelope saying what you want (e.g., "GET: Please send me a package" or "POST: Here is a package to keep").
  • The Headers: The metadata (e.g., Return address, "Fragile", "Overnight Delivery").
  • The Body: The actual contents inside the envelope (the payload).

1. The Structure of an HTTP Request

When your browser or a tool like fetch() makes a request, it generates a raw text string that looks like this:

POST /users/123/profile?theme=dark HTTP/1.1
Host: api.example.com
Authorization: Bearer my_secret_token
Content-Type: application/json

{
  "username": "coder123",
  "bio": "I love distributed systems"
}

Let's break down exactly how this request is formed.

The Endpoint (URL / URI)

The URL defines where the request is going and what it is targeting. It is composed of the base domain, path parameters, and query parameters.

Path Parameters

Variables embedded directly into the URL path, used to identify a specific resource.

Query Parameters

Key-value pairs appended to the end of the URL after a ?.

2. HTTP Methods (Verbs)

The Method tells the server what action you want to perform on the URL.

3. HTTP Headers

Headers are key-value pairs sent alongside the request (or response) that provide critical metadata.

4. The Request Body

The Body contains the actual data payload.

5. The Response (Status Codes)

When the server replies, it sends back a Status Code indicating what happened. You must memorize these categories: