If you write web applications, you probably make or handle dozens of API calls every week. You write fetch('/api/users'), build an endpoint in Express, Go, or FastAPI, and serialize a database record into JSON. We casually call almost all of this "building REST APIs."
Yet during code reviews or architecture discussions, the same questions keep popping up:
- Should this be a PUT or a PATCH?
- Why is
/api/delete-user?id=12considered bad practice? - Why does returning
200 OKwith an error message inside make client developers miserable? - What does REST actually mean, and why did the industry adopt it instead of older tools?
To answer those questions, it helps to step back and look at the problem from the beginning: what an API is, why older distributed systems struggled, and how REST changed how we build for the web.
What is an API in the first place?
Strip away the acronym—Application Programming Interface—and an API is simply a contract between two separate pieces of software.
Think about functions you already use locally:
1// Local API: V8 runtime boundary 2const parsed = JSON.parse(rawString);
Behind JSON.parse(), the V8 JavaScript engine runs complex C++ parsing routines, allocates memory buffers, and navigates syntax trees. You don't need to know any of that. You only care about the contract: give it a valid JSON string, and it returns a JavaScript object.
A Web API is the exact same idea, except the boundary sits across a network:
┌──────────────────┐ HTTP Request ┌──────────────────┐
│ Client App │ ────────────────────────> │ Backend Server │
│ (React / iOS) │ <──────────────────────── │ & Database │
└──────────────────┘ HTTP Response └──────────────────┘
The client application (a Next.js site, an iOS app, or a CLI script) doesn't know whether your backend runs on Go, Node.js, or Java. It doesn't care whether your data lives in PostgreSQL or DynamoDB.
The API establishes the contract:
- Here is the URL you call.
- Here is the HTTP method and payload format to provide.
- Here is the shape of the data and status code you get back.
As long as that contract holds, you can rewrite your entire database schema or replace your backend framework without breaking the client.
The mess before REST: why was it needed?
To understand why REST took over, you have to look at what distributed systems looked like in the 1990s and early 2000s.
When companies started connecting different internal servers across networks, two main patterns dominated:
1. RPC (Remote Procedure Call)
The core pitch of RPC was simple: make calling a remote server feel just like calling a local function.
1// The RPC illusion: 2const result = server.processOrder(customerId, cartItems);
While that sounded convenient, it ignored the physical reality of networks. A local function call finishes in nanoseconds and never fails because a router midway dropped a packet. A network call has latency, partial failures, timeouts, and connection drops.
More importantly, RPC tightly coupled client and server code. If the backend renamed processOrder to submitOrder, or rearranged its parameters, every client application broke immediately.
2. SOAP and XML
In the early 2000s, enterprise vendors pushed SOAP (Simple Object Access Protocol). SOAP attempted to standardize web services, but it brought massive complexity with it.
Even a simple request to fetch a user profile required wrapping everything in a heavy XML envelope:
1<?xml version="1.0"?> 2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 3 <soap:Header> 4 <auth:Token>xyz-token-123</auth:Token> 5 </soap:Header> 6 <soap:Body> 7 <m:GetUserRequest xmlns:m="http://example.com/users"> 8 <m:UserId>42</m:UserId> 9 </m:GetUserRequest> 10 </soap:Body> 11</soap:Envelope>
Every single request was sent as an HTTP POST to a generic endpoint like /ws/UserService.
This approach had three major flaws on the open web:
- Bandwidth waste: Verbose XML structures wasted mobile data and battery life.
- Zero HTTP caching: Because every request was a
POSTto the same URL, intermediate proxies and browsers couldn't cache read operations. - Tooling lock-in: You needed specialized WSDL generators and enterprise parsers just to consume an endpoint.
Roy Fielding and the birth of REST
In 2000, computer scientist Roy Fielding published his doctoral dissertation at UC Irvine titled "Architectural Styles and the Design of Network-based Software Architectures".
Fielding wasn't just observing from academia. He was one of the principal authors of the HTTP/1.0 and HTTP/1.1 specifications, and a co-founder of the Apache HTTP Server project.
He noticed a clear paradox:
While distributed enterprise software was constantly breaking and struggling to scale, the World Wide Web itself was exploding across millions of independent servers, websites, and browsers without central coordination.
Why did the web succeed where enterprise protocols struggled? Because the web was built on a small set of universal conventions: unique identifiers (URIs), standard operations (GET, POST), stateless communication, and standard document formats.
In Chapter 5 of his dissertation, Fielding formalized those principles under a new name:
It is an architectural style for designing networked applications, first introduced by computer scientist Roy Fielding in 2000.
Notice the key phrase: architectural style.
REST is not a protocol, a specification document, or a software library. You don't install REST. It is a set of design constraints for building web services that behave cleanly over the internet.
What does "Representational State Transfer" actually mean?
The name sounds intimidatingly academic, but each word maps to a very straightforward concept:
| Term | What it means in practice | Example |
|---|---|---|
| Resource | The entity or concept you want to work with. | A User, an Order, a Product, a Comment. |
| State | The current data stored in your database. | User 42 has status = "active" and email = "alice@example.com". |
| Representation | How the server packages that data to send over the wire. | A JSON object, an XML document, or CSV. |
| Transfer | Moving that representation between client and server via standard HTTP. | Sending a request, receiving a response. |
When a client calls GET /users/42, the server doesn't give the client direct access to its database row. Instead, it reads the current state of that resource, serializes it into a representation (like JSON), and transfers it over the wire.
When the client sends a PATCH /users/42 with { "status": "suspended" }, it transfers a new desired state back to the server.
The core constraints that actually matter in production
Fielding laid out six architectural constraints. In day-to-day engineering, a few of these do the heavy lifting:
1. Client-Server Separation
The user interface (web browser, mobile app) and data storage/business logic (backend API) live in completely independent worlds.
- You can redesign your React UI or rewrite your iOS app in SwiftUI without changing backend routes.
- You can migrate your database from Postgres to CockroachDB without breaking existing mobile clients.
2. Statelessness
Every incoming HTTP request must contain all the information necessary for the server to process it. The server should not rely on stored session memory in RAM from previous requests.
Request 1: GET /profile (Header: Authorization: Bearer token_abc) -> Server responds
Request 2: GET /orders (Header: Authorization: Bearer token_abc) -> Server responds
Why does statelessness make scaling so much easier?
Imagine you have 5 backend servers sitting behind a load balancer:
- If your system is stateful: Server 1 holds your user session in its memory. Every subsequent request from your device must hit Server 1. If Server 1 restarts or runs out of RAM, your session is wiped.
- If your system is stateless: Because every request carries its own authentication credentials, the load balancer can send Request 1 to Server 1, Request 2 to Server 4, and Request 3 to Server 2. Any server can be killed or redeployed without users noticing.
3. Cacheability
Every HTTP response should explicitly state whether it can be cached, and for how long.
Using standard headers like Cache-Control: public, max-age=3600 or ETag, intermediate CDNs (like Cloudflare or Fastly) and browser caches can serve read traffic directly. If 50,000 users visit the same product page, your database only needs to answer once.
4. Layered System
A client shouldn't need to know whether it is communicating directly with the origin server or through an intermediary.
You can place API gateways, rate-limiters, SSL termination proxies, and load balancers in front of your service. As long as the interface remains standard, the client doesn't need to change.
5. Uniform Interface
All interactions follow consistent rules:
- Resources have unique URIs (
/api/v1/posts/10). - Operations use standard HTTP verbs (
GET,POST,PUT,PATCH,DELETE). - Responses describe themselves with headers (
Content-Type: application/json).
REST in practice: the everyday rules
Here is how these architectural concepts translate into clean, maintainable endpoints.
1. Use nouns for URLs, not verbs
The URL identifies the resource (the noun). The HTTP method defines the action (the verb).
| What you want to do | ❌ RPC Style | ✅ RESTful Style |
|---|---|---|
| Fetch all products | GET /getAllProducts | GET /products |
| Get product #7 | GET /getProduct?id=7 | GET /products/7 |
| Create a new product | POST /createNewProduct | POST /products |
| Update product #7 | POST /updateProduct?id=7 | PATCH /products/7 |
| Delete product #7 | POST /deleteProduct?id=7 | DELETE /products/7 |
Keeping URLs noun-based makes an API predictable. If a developer knows your resource is /orders, they can instantly guess how to list, read, update, or delete them without checking the docs for custom function names.
2. HTTP methods and idempotency
Understanding HTTP verbs avoids subtle bugs in production:
| Method | Role | Safe? | Idempotent? |
|---|---|---|---|
| GET | Retrieve a resource representation | Yes | Yes |
| POST | Create a resource or execute an action | No | No |
| PUT | Replace a resource completely | No | Yes |
| PATCH | Update specific fields on a resource | No | Usually |
| DELETE | Remove a resource | No | Yes |
Two terms here matter:
- Safe: Calling it does not mutate server state.
GETis safe. A search engine crawler following aGETlink should never accidentally delete records or charge credit cards. - Idempotent: Calling the request once produces the same outcome as calling it ten times.
DELETE /articles/5: The first call removes it. Subsequent calls find it already gone. The end state on the server is identical.POST /payments: Not idempotent. If a network hiccup causes the client to retry aPOSTpayment request without an idempotency key, the user could be charged twice.
3. Don't hide errors behind 200 OK
One of the most frustrating patterns in API development is receiving an HTTP 200 OK status with an error payload:
1// ❌ Anti-pattern: HTTP 200 OK with error payload 2{ 3 "success": false, 4 "error": "Resource not found" 5}
This breaks how the web works. Monitoring tools (Datadog, Sentry), API gateways, and client libraries rely on HTTP status codes to detect failures.
Use real status codes:
- 200 OK: Success for read or update operations.
- 201 Created: Success for
POSTthat creates a new resource. - 204 No Content: Success where no response body is needed (e.g.
DELETE). - 400 Bad Request: Client passed malformed JSON or invalid syntax.
- 401 Unauthorized: Missing or invalid authentication token.
- 403 Forbidden: The server knows who you are, but you don't have permission.
- 404 Not Found: The resource doesn't exist.
- 422 Unprocessable Entity: Payload syntax is fine, but business validation failed (e.g. end date is before start date).
- 500 Internal Server Error: An unhandled bug or crash occurred on the server.
Pragmatic REST vs Academic REST
If you look into REST theory, you will eventually encounter the Richardson Maturity Model:
- Level 0: RPC over HTTP (single endpoint, everything
POST). - Level 1: Resources with distinct URLs.
- Level 2: Proper HTTP verbs and status codes.
- Level 3 (HATEOAS): Responses contain hypermedia links instructing the client what actions it can take next.
Example of Level 3 (HATEOAS):
1{ 2 "order_id": 1042, 3 "status": "pending", 4 "_links": { 5 "cancel": { "href": "/orders/1042/cancel", "method": "POST" }, 6 "pay": { "href": "/orders/1042/payments", "method": "POST" } 7 } 8}
Purists argue that an API isn't truly "REST" unless it implements Level 3.
In practice? Almost nobody in the software industry uses Level 3.
Stripe, GitHub, Twilio, and AWS build what is commonly called Pragmatic REST (Level 2). Modern frontend and mobile clients already know their own navigation and business flows. Dynamic hypermedia links add serialization overhead and maintenance complexity without offering much practical benefit. Modern OpenAPI (Swagger) specifications give us typed contracts and documentation much more cleanly.
When should you look beyond REST?
REST is the default choice for web and mobile backends, but it isn't the best tool for every problem:
| Scenario | Best Fit | Why |
|---|---|---|
| Standard CRUD apps, public developer APIs | REST | Universal tooling, built-in caching, easy to test with curl or browser. |
| Complex frontends with deeply relational data | GraphQL | Lets the client request exact fields in one round trip, avoiding over-fetching. |
| High-throughput internal microservices | gRPC | Uses Protocol Buffers (binary serialization) over HTTP/2 for minimal latency and strict code generation. |
Summary: A quick API review checklist
When building or reviewing an API endpoint, keep these simple rules in mind:
- Resources are nouns: Use
/users,/invoices,/teams. Keep them plural and consistent. - Use verbs correctly: Let
GET,POST,PATCH, andDELETEexpress what is happening. - Keep GET requests harmless: A
GETcall should never modify persistent data. - Be honest with status codes: Never return
200 OKfor an error. - Keep requests stateless: Pass tokens in headers (
Authorization: Bearer ...), not in server memory. - Keep URLs reasonably flat: Prefer
/tasks/99over/companies/1/departments/4/teams/8/tasks/99if the ID is globally unique.
REST became the standard of the modern web because it didn't try to reinvent distributed communication. Instead, it embraced the simple, stateless, and decentralized principles that made the World Wide Web work in the first place.



