Representational State Transfer (REST)

From Coder Merlin
Revision as of 10:46, 20 August 2021 by Akshat-sharma (talk | contribs) (Created page with "== What is REST? == REST, or representational state transfer, defines a set of rules that acts as the architecture for interactions with REST web services. It uses HTTP to req...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

What is REST?[edit]

REST, or representational state transfer, defines a set of rules that acts as the architecture for interactions with REST web services. It uses HTTP to request and access data from such services that are broken down to smaller modules that have their own functions.

What is an API?[edit]

An API, Application Programming Interface, is a software interface that facilitates communication between various programs. This allows parties to send requests and receive responses to each other with the intent of transferring data effortlessly. The main usage of APIs are for companies to open up their application to other people, such as third party developers or business partners, and give them access to its functionality and data to aid in collaboration projects or produce new business relationships.

REST Architecture[edit]

  • Client-server architecture: REST’s flexibility comes from the separation of the interface from the data storage, allowing different components to evolve independent of each other.
  • Statelessness: no client context is stored on the server between requests
  • Cache-ability: instead client data is stored in the cache which is faster. REST API response must explicitly state whether it can be cached or not.
  • Layered system: the API will work whether it is communicating directly with a server, or through an intermediary such as a load balancer.
Oooooooooooooooooga.png

REST Process[edit]

Content is broken down into smaller chunks of data that are responsible for its own part of the transaction. The content is retrieved through commands:

  • GET to retrieve a resource
  • PUT to change the state of or update a resource, which can be an object, file or block
  • POST to create that resource
  • DELETE to remove it

REST API Principles[edit]

  • Client-Server Architecture
    • REST APIs follow a Client-Server model; clients request and receive various data to and from a centralized server. This ensures that the client cannot directly interact with the centralized server and the centralized server cannot directly modify the client application. The separation allows for different components to learn from each other. Client-server utilizes HTTP to request and receive data to and from the server.
  • Statelessness
    • The stateless protocol requires client requests to the main server to contain all information necessary to fulfill the request. This includes the previous packets and context information from previous requests and sessions will not interfere with the current and relevant web session. This is advantageous as it allows RESTful interfaces to scale as applications grow in volume; the statelessness increases performance by removing the need of retaining previous session information.
  • Layered Systems
    • The layered architecture employs hierarchical layers that are unable to see beyond the layer that they are interacting with. This increases stability so that layers are unable to accidentally change data from another layer.
  • Uniform Interface

Why use REST?[edit]

One of the biggest advantages of using a REST API comes from the flexibility it provides. As a set of guidelines, REST is able to be used with various data formats, structures, languages, and ultimately allows for developers to frame their program to meet their needs. Additionally, REST APIs can be scaled to fit any size of application or program. A lot of APIs begin to struggle when an application begins to require more resources, but REST is able to handle the increasing size and complexity with ease.

Real World Applications[edit]

Many large companies such as Twitter, Instagram, and Spotify use REST APIs to allow access to their data. In fact, this API structure is so versatile that many developers believe it is on track to becoming the industry standard for APIs in web development.

Roy Fielding.jpg

History[edit]

The REST architectural style was created by Roy Fielding in 1999 where he added it to his 2000 PhD dissertation called “Architectural Styles and the Design of Network-based Software Architectures” at U.C. Irvine. Fielding analyzed the requirements that a world-wide network-based application required for global adoption through surveying existing architectural styles, identifying which features are shared among different styles.

Key Concepts[edit]

Key ConceptsKeyConceptsIcon.png
  • Understanding REST
  • Understanding API

References[edit]