Software-Engineering

REST (Representational State Transfer)

What is REST?

REST (Representational State Transfer) is an architectural style for designing networked applications. It relies on a stateless, client-server, cacheable communications protocol – and in virtually all cases, the HTTP protocol is used. REST is an architectural style, not a standard or protocol itself.

RESTful applications use HTTP requests to post data (create and/or update), read data (make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

How it Works

REST operates on the concept of resources. A resource is any object the API can provide information about (e.g., a user, a product, a tweet).

  1. Resources & URIs: Each resource is identified by a unique URI (Uniform Resource Identifier).
    • Example: GET /users/123 retrieves the user with ID 123.
  2. HTTP Methods: Standard HTTP verbs define the action to be performed on the resource.
    • GET: Retrieve a resource.
    • POST: Create a new resource.
    • PUT: Update an existing resource (full replacement).
    • PATCH: Update an existing resource (partial modification).
    • DELETE: Remove a resource.
  3. Statelessness: Each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client.
  4. Representations: Resources are decoupled from their representation. A server can send data in JSON, XML, HTML, etc., depending on what the client requests (via Accept headers).

Why We Need It & When to Use

REST has become the de-facto standard for web APIs due to its simplicity and alignment with the way the web works.

Use REST when:

Other Options

Pros and Cons

Pros

Cons