Skip to main content

REST

Representational State Transfer

REST (Representational State Transfer) is an architectural style commonly used for designing networked APIs. RESTful APIs use standard HTTP methods - such as GET, POST, PUT, PATCH, and DELETE - to perform operations on resources, which are typically represented as URLs.

Key Principles

  • Stateless: Each request from client to server must contain all necessary information for the server to fulfill the request. The server does not store anything about the latest client request.
  • Resource-Based: Everything is a resource, identified by a unique URL (endpoint).
  • Uniform Interface: Resources are manipulated using a consistent, standardized set of operations.
  • Representation: Resources can have different representations, such as JSON or XML.

Common HTTP Methods

MethodUsage
GETRetrieve a resource or collection
POSTCreate a new resource
PUTReplace a resource entirely
PATCHUpdate part of a resource
DELETERemove a resource

Example

Assume a user resource available at /api/users.

  • Get the list of users: GET /api/users
  • Get details for a specific user: GET /api/users/42
  • Create a new user: POST /api/users
  • Update a user: PUT /api/users/42
  • Delete a user: DELETE /api/users/42

Why REST?

  • Language and platform agnostic (works with anything that can send HTTP requests)
  • Scalable and stateless, making it easy to cache and load balance
  • Human-readable URLs

REST is the most popular choice for modern web APIs, though alternatives like GraphQL are rising for complex data access patterns.