REST (Representational State Transfer) is an architectural style for designing networked applications, most commonly over HTTP. Rather than a rigid standard or protocol, it defines a set of architectural constraints (such as statelessness, resource-based URLs, a uniform interface, and cacheability) for how clients and servers communicate.
An operation is idempotent if making the same request multiple times produces the same result as making it just once. In other words, repeating the operation doesn’t change the outcome after the initial successful execution. Only the state of the server is considered, not the response code.
| Method | Example | Status Code |
|---|---|---|
| GET | /users/:id | 200 OK |
| POST | /users | 201 Created |
| PUT | /users/:id | New: 201 Created; Exists: 200 OK or 204 No Content |
| PATCH | /users/:id | 200 OK or 204 No Content |
Examples
New User
POST /users
{
"name": "Amar"
}- Returns
201 Created - Not idempotent — a new user is created on every request
Get User
GET /users/:id
- Idempotent
Upsert User
PUT /users/:id
{
"name": "Amar"
}- Returns
201 Createdif new, or200 OK/204 No Contentif it already exists - Idempotent
- Replaces the complete representation of the resource
Modify Some Fields
PATCH /users/:id
{
"name": "New name"
}Idempotent Methods
HEAD, OPTIONS, GET, PUT, DELETE, TRACE — see MDN Idempotent.
Cacheable
See MDN Cacheable.