Web APIs
REST Architecture
Explore the foundational structure behind every great API and build your first REST endpoint.
Facebook serves 4.95 billion API calls every day. Netflix streams through thousands of microservices. Shopify processes millions of transactions across borders. Every single one follows the same architectural pattern: REST. Not because it is trendy, but because it works at any scale.Architecture in software development means the high-level design that determines how different pieces fit together. REST architecture defines how web APIs should behave, what URLs should look like, and how servers should respond to different types of requests. It is not a technology or framework — it is a set of principles that makes APIs predictable and scalable.
The acronym REST stands for Representational State Transfer, but that definition helps nobody. Think of it this way: your API represents resources (users, orders, products) and transfers their current state (the data) when clients ask for them. Every resource gets its own URL. Every action uses a specific HTTP method. Every response follows consistent patterns.
Roy Fielding coined the term REST in his doctoral dissertation back in 2000. He was one of the principal authors of HTTP itself, so he understood better than anyone how web protocols actually work. His insight was simple: instead of inventing new ways to communicate over the internet, why not use HTTP the way it was designed to be used?
What REST Architecture Actually Means
Before REST, web services were a mess of competing standards and complex protocols. SOAP required XML schemas longer than entire applications. RPC systems forced you to think in terms of remote function calls rather than web resources. Developers spent more time fighting integration than building features.REST changed everything by treating the web like the web. Instead of pretending HTTP was just a transport layer, REST embraces HTTP as an application protocol. Resources become URLs. Actions become HTTP methods. State becomes response data. Errors become status codes.
A resource in REST terminology is any piece of information your API can provide. Users are resources. Blog posts are resources. Shopping cart items are resources. The current weather in Tokyo is a resource. Each resource gets identified by a unique URL, called a resource identifier.
The key insight is that REST APIs expose resources, not operations. Instead of endpoints like /getUserById or /deleteUser, you get clean resource paths like /users/123. The HTTP method tells you what action to take.
The Resource-Method Matrix
The magic of REST happens when you combine resources with HTTP methods. Every API operation becomes a combination of "which resource" and "what action." This creates a predictable pattern that developers can understand instantly.Think of resources as nouns and HTTP methods as verbs. GET retrieves. POST creates. PUT updates. DELETE removes. This noun-verb combination eliminates guesswork about what an endpoint does. GET /users/456 obviously retrieves user 456. DELETE /orders/789 obviously removes order 789.
Collections and individual items follow consistent patterns too. /users represents all users. /users/123 represents one specific user. POST to the collection creates a new item. GET from the collection retrieves the list. PUT to an individual item updates it.
| Method + Resource | What it does | APIForge use case |
|---|---|---|
| GET /developers | List all developers | Platform admin sees registered developers |
| GET /developers/123 | Get specific developer | Show developer profile and API usage |
| POST /developers | Create new developer | Developer signs up for platform account |
| PUT /developers/123 | Update specific developer | Developer updates profile or billing info |
| DELETE /developers/123 | Remove specific developer | Developer cancels account permanently |
| GET /developers/123/projects | List projects for developer | Dashboard shows all developer's projects |
/developers/123/projects means "projects that belong to developer 123." This creates intuitive relationships between resources that mirror real-world connections.
Statelessness in Practice
REST demands that every request contains everything the server needs to process it. No session memory. No conversation history. Each request stands alone, carrying its own authentication, parameters, and context.This sounds limiting until you realize what it enables. Servers can handle millions of requests without remembering anything about previous ones. Load balancers can route requests to any available server. Caches can store responses without worrying about user state. Systems can scale horizontally by adding more servers.
Statelessness means your API calls look more verbose but behave more predictably. Instead of logging in once and staying authenticated, each request includes an API key or token. Instead of building up context over multiple calls, each request specifies exactly what it wants.
# APIForge developer retrieves their project list
# Every request includes authentication and full context
GET /developers/456/projects HTTP/1.1
Host: api.apiforge.dev
Authorization: Bearer abc123def456ghi789
Accept: application/json
User-Agent: APIForge-Client/2.1.4
Uniform Interface Benefits
The uniform interface constraint is what makes REST APIs learnable. Once you understand one well-designed REST API, you can navigate any other REST API with minimal documentation.Developers expect GET to be safe and idempotent — calling it multiple times produces the same result with no side effects. They expect POST to create resources and return 201 Created on success. They expect DELETE to remove resources and return 204 No Content.
This consistency reduces cognitive load. Developers don't need to memorize custom conventions for every API they integrate. Error handling follows HTTP status code patterns. Authentication uses standard header formats. Response structures follow predictable JSON conventions.
GitHub's API exemplifies uniform interface design. Whether you are managing repositories, issues, or pull requests, the patterns stay consistent.GET /repos/owner/name gets repository details. GET /repos/owner/name/issues gets issues for that repository. POST /repos/owner/name/issues creates a new issue.
# APIForge API follows uniform interface patterns
# Creating a new API key follows standard REST conventions
POST /developers/456/api-keys HTTP/1.1
Host: api.apiforge.dev
Authorization: Bearer abc123def456ghi789
Content-Type: application/json
{
"name": "Production Mobile App",
"permissions": ["projects:read", "usage:read"],
"expires_at": "2025-01-15T00:00:00Z"
}
Layered Architecture Advantages
REST systems work through layers, and each layer only knows about the layers immediately next to it. Your client talks to a load balancer. The load balancer talks to application servers. Application servers talk to databases. Nobody needs to understand the entire system.This layered approach enables powerful optimizations. CDNs cache responses at the edge. Reverse proxies handle SSL termination. Application servers focus on business logic. Database servers handle data persistence. Each layer optimizes for its specific purpose.
Stripe processes hundreds of thousands of payments per minute through layered REST architecture. API requests hit their edge servers first, which handle authentication and basic validation. Approved requests flow to application servers that process business logic. Database operations happen on specialized storage layers. Error responses can come from any layer, but they all follow the same REST patterns.
Cache-Friendly Design
REST embraces HTTP caching mechanisms that can dramatically improve performance. Cache-Control headers tell clients and intermediaries how long responses stay valid. ETags enable conditional requests that save bandwidth. Proper caching can reduce API calls by 60% or more.GET requests should always be cacheable unless they contain sensitive data. Resource representations with stable URLs cache better than dynamic ones. Timestamps and version numbers in responses help clients understand when data changes.
The APIForge team needs to balance data freshness with performance. Developer profile information changes rarely and can cache for hours. API usage statistics change frequently and cache for minutes. Real-time alerts never cache.
# APIForge serves cached developer profile data
# Cache headers optimize for both freshness and performance
GET /developers/456 HTTP/1.1
Host: api.apiforge.dev
Authorization: Bearer abc123def456ghi789
If-None-Match: "dev456-v23"
HATEOAS and Discoverability
HATEOAS stands for Hypermedia as the Engine of Application State, which sounds intimidating but describes something simple: APIs should include links to related resources and available actions.Instead of requiring clients to construct URLs manually, well-designed REST APIs provide navigation links in responses. If a developer has projects, the developer resource includes links to those projects. If a project can be deleted, the project resource includes a delete link with the proper URL and method.
Few APIs implement full HATEOAS because it adds complexity, but the principle still guides good design. Resource relationships should be discoverable. Available actions should be obvious. URL construction should follow predictable patterns so clients can navigate without hardcoding paths.
Quiz
1. The APIForge Backend team needs to implement stateless requests. What does this requirement mean for their API design?
2. APIForge wants to create a new project for developer ID 123. Which REST endpoint follows proper resource-method conventions?
3. What advantage does REST's layered architecture provide for the APIForge platform as it scales?