What is a REST API?
Learn what a REST API is — resources, HTTP verbs, statelessness and status codes — with examples, common mistakes and web development interview questions.
Expected Interview Answer
A REST API is a web interface that exposes data as resources identified by URLs, which clients manipulate using standard HTTP methods (GET, POST, PUT, PATCH, DELETE) over stateless requests that each carry all the information the server needs.
REST (Representational State Transfer) is an architectural style, not a protocol. Resources such as /users or /users/42 are addressed by URLs, and the HTTP verb expresses the intent: GET reads, POST creates, PUT/PATCH updates, DELETE removes. Every request is stateless — the server keeps no client session between calls — and responses use standard status codes (200, 201, 404, 500) and a representation format, usually JSON. Well-designed REST APIs use nouns for endpoints, are cacheable, and offer a uniform, predictable interface.
- Uses standard, well-understood HTTP verbs and status codes
- Stateless requests scale horizontally with ease
- Language-agnostic — any HTTP client can consume it
- Cacheable responses improve performance
AI Mentor Explanation
A REST API is like the scoreboard operator following a fixed protocol. Each element — a batter, an over, the total — is an addressable item, and the actions are standardized: request the current score, add a run, update a wicket, remove a no-ball. The operator never remembers who asked last; every instruction must name the item and the action in full. That addressable-item-plus-standard-action-plus-no-memory pattern is exactly how REST exposes resources over stateless HTTP.
Step-by-Step Explanation
Step 1
Model resources as URLs
Use nouns like /users and /users/42 — each resource has a stable address.
Step 2
Map actions to HTTP verbs
GET reads, POST creates, PUT/PATCH updates, DELETE removes.
Step 3
Keep it stateless
Each request carries all it needs (auth, params); the server stores no client session.
Step 4
Return status + representation
Reply with standard codes (200, 201, 404) and a representation, usually JSON.
What Interviewer Expects
- Resource-based URLs plus HTTP verbs as the core idea
- Statelessness of every request
- Correct use of status codes and JSON representations
- REST as an architectural style, not a protocol
Common Mistakes
- Putting verbs in URLs (/getUser) instead of using HTTP methods
- Confusing REST with a specific technology or protocol
- Storing client state on the server between requests
- Ignoring proper status codes and returning 200 for everything
Best Answer (HR Friendly)
“A REST API is a standard way for programs to talk over the web. Each piece of data has its own web address, and you use simple actions — read, create, update, delete — to work with it. Because each request is self-contained, REST APIs are easy to scale and any language can use them.”
Code Example
GET /users -> 200 list all users
GET /users/42 -> 200 read one user
POST /users -> 201 create a user (body: JSON)
PUT /users/42 -> 200 replace a user
PATCH /users/42 -> 200 update fields on a user
DELETE /users/42 -> 204 delete a userFollow-up Questions
- What is the difference between REST and GraphQL?
- What makes an API idempotent, and which verbs are idempotent?
- What are the most common HTTP status codes and their meaning?
- What does statelessness mean for scaling a REST API?
MCQ Practice
1. Which HTTP method is used to create a new resource in REST?
POST sends data to create a new resource under a collection endpoint.
2. A REST API being stateless means?
Each request carries all needed context; the server holds no per-client session.
3. Which is the most RESTful URL to fetch user 42?
REST uses noun-based resource paths; the GET verb already implies fetching.
Flash Cards
What does REST stand for? — Representational State Transfer — an architectural style for web APIs.
How does REST express intent? — Through HTTP verbs: GET read, POST create, PUT/PATCH update, DELETE remove.
What does stateless mean in REST? — Each request is self-contained; the server stores no client session between calls.
Typical REST response format? — A status code plus a representation of the resource, usually JSON.