---
slug: oip-what-is-rest
title: What Is REST
canonical: https://miscsubjects.com/a/oip-what-is-rest
---

REST is not a protocol. It is an architectural style that treats the entire web as a collection of resources, each addressable by a unique URL, manipulated through a small set of universal verbs.

Every REST interaction is stateless. The server forgets you after every request. You carry your context in the request itself — the URL, the headers, the body. This is not a limitation. It is the discipline that makes the web scale.

## What It Is

**REST (Representational State Transfer) is an architectural style for designing networked applications. It uses HTTP methods (GET, POST, PUT, DELETE, PATCH) to operate on resources identified by URLs. Each request from client to server must contain all the information needed to understand and process the request. The server stores no client session state between requests.**

REST was coined by Roy Fielding in his 2000 doctoral dissertation. He did not invent it. He named what the web was already doing and distilled the constraints that made it work.

## Why It Matters

The web won because it is simple. REST preserves that simplicity.

Before REST, distributed systems were a nightmare of custom protocols, binary wire formats, and fragile session state. CORBA, SOAP, DCOM — each required heavy tooling, thick clients, and tight coupling between systems. They were brittle. They broke when versions changed. They locked you into vendor stacks.

REST changed the game. It said: use what exists. HTTP is already universal. URLs are already addressable. JSON is already readable. Stateless interactions mean any server can handle any request. Caching becomes trivial. Load balancing becomes trivial. Scaling becomes a matter of adding more boxes, not rewriting architecture.

Philosophically, REST embodies a profound principle: **uniform interface over hidden complexity**. The client does not need to know the database schema, the programming language, or the internal state machine. It sends a verb to a noun. The noun handles it. This separation of concerns is the foundation of all durable software.

REST matters because it is the closest thing we have to a universal machine-to-machine language. Every programming language speaks HTTP. Every platform understands URLs. REST is the lingua franca of integration.

## How It Works

REST is built on six constraints. Four of them matter most in practice.

**1. Client-Server Separation**

The client and server are independent. The client handles the user interface. The server handles data and logic. They evolve separately. You can rewrite the server in Go without touching the client. You can ship a new mobile app without touching the API.

**2. Stateless**

Each request is self-contained. The server does not remember who you are. If you need continuity, you send a token (JWT, API key, session cookie) with every request. The server validates it fresh each time. No server-side session storage. No sticky sessions. No single point of failure.

**3. Cacheable**

Responses must explicitly declare themselves cacheable or not. A GET response that says `Cache-Control: max-age=3600` can be stored by intermediaries and reused. This eliminates redundant work. It is why a CDN can serve millions of requests without ever hitting your origin.

**4. Uniform Interface**

This is the core. Four sub-constraints govern it:

- **Resource identification**: Every resource has a URL. `https://api.example.com/users/42`. Not `/getUser.php?id=42`. The URL names the thing, not the action.
- **Manipulation through representations**: The client sends or receives a representation of the resource (usually JSON), not the resource itself. The server translates.
- **Self-descriptive messages**: Each request and response contains all metadata needed to interpret it. Method, headers, status code, body. No out-of-band context.
- **Hypermedia as the engine of application state (HATEOAS)**: A response contains links to related actions. The client discovers what it can do next from the response itself. This is REST in its pure form, though often ignored in practice.

**Concrete Example: Ordering a Book**

You want to buy a book from an online store. The RESTful interaction looks like this:

`GET /books/978-0-13-468599-1`

The server responds with the book's representation:

```json
{
  "id": "978-0-13-468599-1",
  "title": "Clean Architecture",
  "author": "Robert C. Martin",
  "price": 42.99,
  "links": {
    "add_to_cart": "/cart/items",
    "reviews": "/books/978-0-13-468599-1/reviews"
  }
}
```

You add it to your cart by POSTing to the `add_to_cart` link:

```
POST /cart/items
Content-Type: application/json

{
  "book_id": "978-0-13-468599-1",
  "quantity": 1
}
```

The server responds:

```json
{
  "cart_item_id": "ci-12345",
  "links": {
    "checkout": "/checkout",
    "remove": "/cart/items/ci-12345"
  }
}
```

You discover the checkout action from the response. No documentation required. No hardcoded URLs. The API teaches you how to use it.

## The Contract

REST is not a specification. It is a set of constraints. But in practice, a RESTful interface follows an exact contract.

**The Resource Contract**

Every resource is a noun. Plural nouns for collections. Singular nouns for specific items.

| URL Pattern | Meaning |
|-------------|---------|
| `/users` | Collection of all users |
| `/users/42` | The specific user with id 42 |
| `/users/42/orders` | Orders belonging to user 42 |
| `/users/42/orders/7` | Specific order 7 of user 42 |

**The Method Contract**

| Method | Action | Idempotent | Safe |
|--------|--------|------------|------|
| GET | Retrieve a resource | Yes | Yes |
| POST | Create a sub-resource | No | No |
| PUT | Replace a resource entirely | Yes | No |
| PATCH | Partially modify a resource | No | No |
| DELETE | Remove a resource | Yes | No |

Idempotent means doing it twice is the same as doing it once. Safe means it does not change state. GET must be both. POST is neither. DELETE is idempotent but not safe (the first call removes the resource; the second returns 404, but the state is the same).

**The Status Code Contract**

| Code | When to Use |
|------|-------------|
| 200 OK | Success, returning a body |
| 201 Created | POST succeeded, new resource exists |
| 204 No Content | Success, nothing to return (DELETE, empty PUT) |
| 400 Bad Request | Client sent malformed data |
| 401 Unauthorized | Client must authenticate |
| 403 Forbidden | Client is authenticated but not authorized |
| 404 Not Found | Resource does not exist |
| 409 Conflict | Request conflicts with current state |
| 422 Unprocessable | Semantics wrong (e.g., validation failed) |
| 500 Internal Server | Server broke, client did nothing wrong |

**The Header Contract**

```
Content-Type: application/json         # What I am sending
Accept: application/json               # What I want back
Authorization: Bearer <token>          # Who I am
Cache-Control: no-cache               # Bypass cache
ETag: "abc123"                        # Resource version for conditional requests
If-None-Match: "abc123"               # Send 304 if unchanged
```

**The Representation Contract**

JSON is the default. XML is acceptable but declining. Form-encoded for simple POSTs. The server must declare what it sends (`Content-Type`). The client must declare what it accepts (`Accept`). Content negotiation is not optional.

## Real Examples

**1. GitHub API**

GitHub's API is the gold standard. `GET /repos/{owner}/{repo}/issues` returns issues. `POST /repos/{owner}/{repo}/issues` creates one. Pagination is handled via `Link` headers, not custom query parameters. Every resource has a consistent URL pattern. The API is versioned in the URL (`/v3/`), not in headers. This is pragmatic REST, not pure REST, but it is excellent.

**2. Stripe API**

Stripe built a billion-dollar company on a REST API. Their design philosophy: "make the right thing easy." Create a charge: `POST /v1/charges`. Retrieve it: `GET /v1/charges/{id}`. List charges: `GET /v1/charges`. Refund: `POST /v1/refunds`. Every object has a consistent CRUD pattern. Errors return structured JSON with `type`, `code`, `message`, and `decline_code`. The API is so predictable that you can write a generic Stripe client in any language without knowing the domain.

**3. Twitter/X API v2**

Twitter's v2 API corrected the v1 disaster. V2 uses resource expansion (`expansions=author_id`), field filtering (`tweet.fields=created_at,public_metrics`), and proper pagination tokens. `GET /2/tweets/{id}` returns a tweet. `GET /2/users/{id}/tweets` returns a user's timeline. The design is RESTful: noun-based URLs, consistent JSON structure, predictable errors.

**4. Cloudflare API**

The API that powers this very build. `GET /zones/{zone_id}/dns_records` lists DNS records. `POST /zones/{zone_id}/dns_records` creates one. `PUT /zones/{zone_id}/dns_records/{record_id}` updates. `DELETE /zones/{zone_id}/dns_records/{record_id}` removes. Every resource is addressable. Every action maps to a standard HTTP method. The API is fully auditable, fully deterministic, and fully scriptable.

**5. Your Browser Right Now**

The web itself is REST. When you loaded this page, your browser sent `GET /articles/oip-what-is-rest`. The server returned HTML (a representation). The page contains links to other resources. You click a link. The browser sends another GET. No state is stored on the server about your "session" unless you explicitly send a cookie. The web is REST's original and most successful implementation.

## Common Mistakes

**Using verbs in URLs.**

Wrong: `POST /createUser`, `GET /getUser/42`, `POST /deleteOrder/7`

Right: `POST /users`, `GET /users/42`, `DELETE /orders/7`

The URL names the resource. The HTTP method names the action. Do not mix them.

**Treating GET as a command.**

GET must not modify state. It must be safe and cacheable. If a GET deletes a resource, every cache, every proxy, every browser prefetch will destroy your data. Never use GET for mutations. Never.

**Returning 200 on errors.**

Wrong: `HTTP 200 OK` with body `{"error": "not found"}`

Right: `HTTP 404 Not Found` with body `{"error": "not found"}`

Status codes are part of the contract. Respect them. A monitoring system that checks 200 to determine health will miss every error you bury in a 200.

**Ignoring idempotency.**

If a client retries a POST because the network timed out, you create a duplicate resource. POST is not idempotent. For operations that must be safe to retry, use PUT with a client-generated ID, or implement idempotency keys. Stripe's `Idempotency-Key: {uuid}` header is the correct pattern.

**Inventing custom headers instead of using standard ones.**

Wrong: `X-Request-ID: 12345` (for request tracing, use `Traceparent` or `X-Request-ID` as standard practice is fine, but inventing `X-My-Custom-Token` instead of `Authorization` is not)

Use `Authorization` for auth. Use `Content-Type` for payload type. Use `ETag` and `If-None-Match` for caching. Do not reinvent what already exists.

**Exposing internal IDs or database schemas.**

Wrong: `GET /api/v1/getCustomerRecord?table=customers&id=42`

Right: `GET /customers/42`

The URL is a public interface. It is not a SQL query. Hide the implementation. Expose the intent.

**Ignoring hypermedia.**

Most APIs ignore HATEOAS. They return bare JSON with no links. The client must hardcode URLs. When the API changes, the client breaks. This is not REST. It is HTTP-RPC with JSON. If you want the durability REST promises, include links. Teach the client what it can do next.

## Connection to OIP

OIP — the Open Interface Protocol — is built on the same principles that make REST endure. REST is the spiritual ancestor of OIP's design philosophy. The connection is direct and intentional.

**Open.** REST is open because it uses universal standards. HTTP is not owned by anyone. JSON is not owned by anyone. A REST API can be consumed by any client written in any language on any platform. OIP extends this: not just open standards, but open contracts. Every row in the OIP directory is readable, editable, and verifiable by anyone with permission. There is no hidden behavior. The tool contract is the contract.

**Deterministic.** REST is deterministic because a given request always produces the same response (assuming the resource has not changed). GET `/users/42` today returns the same structure as GET `/users/42` tomorrow. OIP takes this further: every tool invocation is logged, every parameter is validated, every output is predictable from the input. There are no side effects that are not declared. The contract is the code.

**Auditable.** REST is auditable because every interaction is a request-response pair with a URL, a method, headers, and a status code. OIP makes this explicit: every turn, every tool call, every decision is recorded in a ledger. You can reconstruct exactly what happened. You can replay it. You can verify it. The audit trail is not an afterthought. It is the system.

REST taught us that the best protocols are the ones that do the least. OIP follows that lesson. A REST API with three verbs and clear nouns is more powerful than a SOAP API with a hundred custom methods. An OIP directory with clean rows and validated contracts is more powerful than a black-box agent with hidden prompts.

REST is the proof that simplicity scales. OIP is the continuation of that proof into the age of agentic systems. The web is REST. The build is OIP. Both rely on the same truth: **when the interface is clean, the system becomes unstoppable.**

## Connection to the Grain Philosophy

This protocol is part of the [Open Inventory Protocol](/a/philosophy) — a living system of self-describing voxels that serves the Grain philosophy. The OIP is the interface. The philosophy is the core.

