REST API HTTP Basics

REST APIs run on top of HTTP — the same protocol your browser uses to load web pages. Before designing an API, you need to understand how HTTP works, because REST borrows all of its mechanics directly from it.

What Is HTTP?

HTTP stands for HyperText Transfer Protocol. It is a set of rules for how computers exchange information over the internet. Think of it as a common language that every web client and server speaks.

When you type a URL into a browser, your browser sends an HTTP request to a server. The server reads that request and sends back an HTTP response — usually an HTML page or, in the case of an API, data in JSON format.

The Structure of an HTTP Request

Every HTTP request has three main parts:

┌─────────────────────────────────────────────┐
│  REQUEST LINE                               │
│  GET /products/42 HTTP/1.1                  │
├─────────────────────────────────────────────┤
│  HEADERS                                    │
│  Host: api.shop.com                         │
│  Accept: application/json                   │
│  Authorization: Bearer abc123               │
├─────────────────────────────────────────────┤
│  BODY (optional)                            │
│  { "name": "Laptop", "price": 75000 }       │
└─────────────────────────────────────────────┘
  • Request Line – the method (GET), the path (/products/42), and the HTTP version
  • Headers – extra information about the request, like content type and authentication
  • Body – data sent to the server (used when creating or updating something)

The Structure of an HTTP Response

The server replies with a response that also has three parts:

┌─────────────────────────────────────────────┐
│  STATUS LINE                                │
│  HTTP/1.1 200 OK                            │
├─────────────────────────────────────────────┤
│  HEADERS                                    │
│  Content-Type: application/json             │
│  Content-Length: 89                         │
├─────────────────────────────────────────────┤
│  BODY                                       │
│  { "id": 42, "name": "Laptop",              │
│    "price": 75000 }                         │
└─────────────────────────────────────────────┘
  • Status Line – whether the request succeeded or failed (200 OK, 404 Not Found, etc.)
  • Headers – metadata about the response, like content type
  • Body – the actual data the server is returning

HTTP Methods: The Verbs of the Web

HTTP defines a set of methods (also called verbs) that tell the server what kind of action the client wants to perform. REST APIs map these methods to database operations.

HTTP Method   │  Action          │  Database Equivalent
──────────────┼──────────────────┼─────────────────────
GET           │  Read data       │  SELECT
POST          │  Create new data │  INSERT
PUT           │  Replace data    │  UPDATE (full)
PATCH         │  Update part     │  UPDATE (partial)
DELETE        │  Remove data     │  DELETE

What Is a URL?

URL stands for Uniform Resource Locator. It tells the server exactly which resource you are interested in. A URL in a REST API looks like this:

https://api.shop.com/products/42
  │          │          │      │
  │          │          │      └── Resource ID (product #42)
  │          │          └── Resource type (products)
  │          └── Domain (the server)
  └── Protocol (HTTPS)

HTTP vs HTTPS

HTTPS is HTTP with encryption added. The S stands for Secure. Always use HTTPS for your APIs — it encrypts data in transit so no one can intercept what the client and server are exchanging. Sending an API key or a password over plain HTTP is dangerous.

Stateless Communication

HTTP is stateless, which means each request is completely independent. The server does not remember anything from previous requests.

Request 1: GET /users/5
Server responds: { "name": "Priya" }
               (Server forgets this conversation)

Request 2: GET /orders/101
Server responds — but has NO memory of Request 1

This stateless nature is actually a feature, not a bug. It makes APIs simple, scalable, and easy to debug. Every request carries all the information the server needs to respond.

What Is JSON?

While HTTP defines how data is transferred, JSON (JavaScript Object Notation) defines how data is formatted. Most REST APIs send and receive data in JSON because it is lightweight, human-readable, and works in every programming language.

{
  "id": 42,
  "name": "Wireless Headphones",
  "price": 2999,
  "inStock": true,
  "tags": ["electronics", "audio"]
}

Key Points

  • HTTP is the foundation of all REST APIs
  • Every HTTP interaction has a request (from client) and a response (from server)
  • HTTP methods (GET, POST, PUT, PATCH, DELETE) define the action being taken
  • Status codes in the response tell the client if the request succeeded or failed
  • Always use HTTPS to keep data secure
  • HTTP is stateless — each request stands alone

Leave a Comment