What Is REST?
REST is an architectural style introduced by Roy Fielding in 2000. It is a set of guidelines for designing networked applications over HTTP. REST is not a protocol, library, or framework. In REST, everything is a resource (a user, order, product) identified by a unique URL. Clients interact with resources using standard HTTP methods.The 6 REST Constraints
1
Client-Server
Client (handles UI) and server (handles data/logic) are separate systems communicating over HTTP. Each can evolve independently.
2
Stateless
The server stores NO client session state between requests. Every request must contain all information needed. Authentication tokens, not server sessions.
3
Cacheable
Responses must indicate whether they can be cached. Caching reduces server load for repeated requests.
4
Uniform Interface
All resources use consistent URL patterns and HTTP methods. The API is predictable regardless of resource type.
5
Layered System
The client cannot tell if it is connected to the actual server or an intermediary (load balancer, cache, gateway). Layers are transparent.
6
Code on Demand (optional)
Servers can send executable code to clients (e.g., JavaScript). Rarely used. The only optional constraint.
Stateless is the most exam-relevant constraint. It means the server never stores session data in memory. Each request from a client must include auth credentials (like a JWT token). This enables horizontal scaling.
HTTP Methods
Idempotent = calling the same operation multiple times gives the same result. Safe = the operation does not change server state.
HTTP Status Codes
Memorize these. Exams test status code knowledge heavily.URL Design Best Practices
1
Use nouns, not verbs
The HTTP method is the verb. The URL is the noun.
2
Use plural resource names
3
Use nesting for relationships
4
Use lowercase with hyphens
Request and Response Anatomy
HTTP Request
HTTP Response
REST vs SOAP vs GraphQL
Full /users Route Example in Express
app.js:
Testing with Postman
1
Create a request
Open Postman, click New > HTTP Request.
2
Set method and URL
e.g., POST http://localhost:3000/api/v1/users
3
Add Content-Type header
Headers tab:
Content-Type: application/json4
Add body
Body tab > raw > JSON:
{"name": "Alice", "email": "alice@test.com"}5
Send and inspect
Click Send. Check the status code and response body.