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.

See also: HTTP, CORS

MethodExampleStatus Code
GET/users/:id200 OK
POST/users201 Created
PUT/users/:idNew: 201 Created; Exists: 200 OK or 204 No Content
PATCH/users/:id200 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 Created if new, or 200 OK / 204 No Content if 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