REST(1), In Concept

Web API is a popular tool used for current middle-tier development. Web API is based on the concept of REST. These two articles are summaries of REST and REST-related issues with my understanding.
The second article was my learning notes several years agao, summarying the REST features, related issues and my understanding. When I tried to rewrite them into an article, I found out that I should review and briefly summarize the basic concept of REST, but that is not just easy work and can be done in several words or sentences. Then I think I'd better write another article for the basic concept of REST, that is this one.
 

Introduction

 
This will be the contents of this article,
  • What is REST
  • Guiding Principles of REST
  • Rules of REST API
  • Advantages and disadvantages of REST API
  • CRUD relates to a REST API

A: What is REST[ref]

 
REST is an acronym for REpresentational State Transfer. It is an architectural style for distributed hypermedia systems and was first presented by Roy Fielding in 2000 in his famous dissertation.
 
What is RESTful?
RESTful is typically used to refer to web services implementing such an architecture. A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. 
 

B: Guiding Principles of REST[ref][ref]

 
REST has its own 6 guiding constraints which must be satisfied if an interface needs to be referred to as RESTful. These principles are listed below.
  1. Client-server
    Architecture made up of clients, servers, and resources, with requests managed through HTTP..
     
  2. Stateless
    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.
     
  3. Cacheable
    Cache constraints require that the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.
     
  4. Uniform interface 
    By applying the software engineering principle of generality to the component interface, the overall system architecture is simplified and the visibility of interactions is improved. In order to obtain a uniform interface, multiple architectural constraints are needed to guide the behavior of components. REST is defined by four interface constraints: identification of resources; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of application state.
     
  5. Layered system
    The layered system style allows an architecture to be composed of hierarchical layers by constraining component behavior such that each component cannot “see” beyond the immediate layer with which they are interacting.
     
  6. Code on demand (optional)
    REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts. This simplifies clients by reducing the number of features required to be pre-implemented.

C: Rules of REST API[ref]

 
There are certain rules which should be kept in mind while creating REST API endpoints.
  • REST is based on the resource or noun instead of action or verb-based. It means that a URI of a REST API should always end with a noun. Example: /api/users is a good example, but /api?type=users is a bad example of creating a REST API.
  • HTTP verbs are used to identify the action. Some of the HTTP verbs are – GET, PUT, POST, DELETE, UPDATE, PATCH.
  • A web application should be organized into resources like users and then uses HTTP verbs like – GET, PUT, POST, DELETE to modify those resources. And as a developer it should be clear that what needs to be done just by looking at the endpoint and HTTP method used.
REST(1), In Concept
  • Always use plurals in URLs to keep an API URI consistent throughout the application.
  • Send a proper HTTP code to indicate a success or error status.
Note[Microsoft]
REST is an architectural style for building distributed systems based on hypermedia. REST is independent of any underlying protocol and is not necessarily tied to HTTP. However, most common REST implementations use HTTP as the application protocol.
 

D: Advantages and disadvantages of REST API[ref]

 
Advantages of REST API
  • REST API is easy to understand and learn, due to its simplicity, known API.
  • With REST API, being able to organize complicated applications & makes it easy to use resources.
  • The high load can be managed with help out of HTTP proxy server & cache.
  • REST API is easy to explore and discover.
  • It makes it simple for new clients to work on other applications, whether it is designed specifically for purpose or not.
  • Use standard HTTP procedure call-outs to retrieve data and requests.
  • REST API depends on codes, can use it to synchronize data with a website without any complications.
  • Users can avail access to the same standard objects and data model when compared to SOAP-based web services.
  • Brings flexible formats by serializing data in XML or JSON format.
  • Allows Standard-based protection with the use of OAuth protocols to verify your REST requests.
Disadvantages or Challenges in REST
  • Lack of state
    most web applications require stateful mechanisms. Suppose you purchase a website which has a mechanism to have a shopping cart. It is required to know the number of items in the shopping cart before the actual purchase is made. This burden of maintaining the state lies on the client, which makes the client application heavy and difficult to maintain.
  • Last of security
    REST doest impose security such as SOAP. That is the reason REST is appropriate for public URLs, but it is not good for confidential data passage between client and server.

E: CRUD relates to a REST API[ref]

 
In the following table, the rows show the tight relationship between CRUD, HTTP, and REST (This is one understanding of ...).
 
REST(1), In Concept
 

Summary

 
This article is understanding of the concept of REST and RESTful Service. The next article, REST(2), RESTFUL Services/Architecture vs. REST based Services/Architecture, will be the understanding of REST in practice.
 
Reference


Similar Articles