What is a REST API and what are the core principles of REST?
Learn what a REST API is and the core principles of REST — resources, statelessness, uniform interface, caching — with examples and interview-ready answers.
Expected Interview Answer
A REST API is a web interface that lets systems exchange data over HTTP by treating everything as a resource identified by a URL and manipulated with standard HTTP methods. REST (Representational State Transfer) is an architectural style built on constraints like statelessness, a uniform interface, and a client-server separation.
Instead of exposing remote procedures, REST exposes resources (users, orders, products) at addressable URLs, and clients act on them using GET, POST, PUT, PATCH and DELETE. Each request carries all the context the server needs, responses are self-descriptive (often JSON), and hypermedia links can guide the client to related actions. The core REST constraints are client-server separation, statelessness, cacheability, a uniform interface, a layered system, and optional code-on-demand.
- Simple and language-agnostic over plain HTTP
- Scales well because requests are stateless
- Cacheable responses reduce load and latency
- Uniform interface makes APIs predictable
- Decouples clients from server implementation
AI Mentor Explanation
Think of REST as the standardized signals an umpire uses on the field. A raised finger always means out, arms wide always means wide, no matter which match or umpire. Every fielding side and batter understands the same fixed vocabulary, so nothing needs explaining mid-game. A REST API works the same way: fixed HTTP verbs and status codes form a uniform interface any client already understands without custom instructions.
Step-by-Step Explanation
Step 1
Identify resources
Model your domain as nouns like /users, /orders, /products, each with a stable URL.
Step 2
Choose HTTP methods
Map actions to verbs: GET to read, POST to create, PUT/PATCH to update, DELETE to remove.
Step 3
Keep it stateless
Every request carries all context (auth token, parameters); the server stores no session between calls.
Step 4
Return self-descriptive responses
Send appropriate status codes and a representation, usually JSON, describing the resource.
Step 5
Enable caching
Mark cacheable responses with headers like Cache-Control and ETag to cut latency and load.
What Interviewer Expects
- Clear definition of REST as an architectural style
- Knowledge of the core REST constraints
- Resource-and-verb thinking rather than RPC
- Understanding of statelessness and cacheability
- Ability to give a concrete resource/URL example
Common Mistakes
- Confusing REST with any HTTP or JSON API automatically
- Putting verbs in URLs like /getUser instead of /users
- Claiming REST requires JSON specifically
- Ignoring statelessness and using server sessions
- Not knowing the six REST constraints
Best Answer (HR Friendly)
“A REST API is a standard way for two systems to talk over the web by treating data as resources you fetch or change with simple, well-known commands. It follows a set of rules that keep it predictable, scalable, and easy for different technologies to use together.”
Code Example
GET /api/users/42 HTTP/1.1
Host: example.com
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=60
{
"id": 42,
"name": "Ada Lovelace",
"links": { "orders": "/api/users/42/orders" }
}Follow-up Questions
- What are the six architectural constraints of REST?
- How does REST differ from SOAP and GraphQL?
- What does HATEOAS mean and why does it matter?
- How do you design good resource URLs?
- What makes an API RESTful versus just HTTP-based?
MCQ Practice
1. What does REST stand for?
REST stands for Representational State Transfer, an architectural style for distributed hypermedia systems.
2. Which of these is a core REST constraint?
Statelessness is one of REST's core constraints; each request must contain all information needed to process it.
3. Which URL is the most RESTful for fetching one user?
REST models resources as nouns, so /users/42 addresses the user resource and GET reads it, avoiding verbs in the path.
Flash Cards
What is REST? — Representational State Transfer, an architectural style for building web APIs around resources and HTTP.
Name the REST constraints. — Client-server, stateless, cacheable, uniform interface, layered system, and optional code-on-demand.
What is a resource in REST? — Any addressable entity (user, order) identified by a stable URL and represented, often as JSON.
Verbs in the URL — RESTful? — No. Use nouns for URLs and HTTP methods (GET, POST, PUT, DELETE) to express the action.