Enroll in Selenium Training

In our previous article, we have thoroughly learned about REST services and the set of constraints that bound us to industry standards. Additionally, we may employ specific architectural elements in our software application to get the desirable results with optimum performance. These REST architectural elements form the key conceptual elements of a Restful service. The below representation shows the key architectural elements along with the constraints in a REST architecture-

Rest Architectural Elements

In this article, we will focus on these three different classes of the architectural elements identified by REST :

  • What are Connectors?
  • Components in REST architectural elements.
  • What are Data Elements?
    • Types of data elements.

What are Connectors?

REST uses connectors that manage communication between the different components. There are five types of connectors that encapsulate the activities of accessing resources. They also enable transferring of resource representations. All the communication through the connectors is hidden with clean separation thereby enhancing the simplicity. There are following REST connector types-

  1. Client - It initiates communication by sending requests and consumes the response sent by the server. Examples are HTTP library, client-side web API like libwww.
  2. Server - It listens for connections and gives responses to the requests hence allowing access to its services. Examples are Web server APIs like Apache API, NSAPI, etc.
  3. Cache - It is the third connector type which is located at either the client or server connector. It stores cacheable responses that can be reused for similar interactions. It saves repeated network communication when employed at the client connector. Alternatively, at the server connector, it saves the repeated response generation process. Examples are the browser cache or web caching solutions like the Microsoft Azure CDN.
  4. Resolver - It translates the resource identifiers into the network address. You know that most of the URIs consist of DNS hostname. Now the web browser extracts the hostname from the URI and uses the DNS resolver to fetch the IP address for the naming authority of the resource. Examples are Microsoft DNS, BIND, etc.
  5. Tunnel - It relays information across the connection boundary like the firewall or gateways. REST components may switch from active to tunnel behaviour. Hence, allowing the client to directly interact with a remote server using a protocol like TLS. Examples are SOCKS, HTTP Tunnel, etc.

Components in Rest Architectural Elements

Components in REST architectural elements are the different software that interacts with each other. They act as end-points connected through connectors and exchanging data elements. There are mainly categorized into four types as described below-

  1. Origin Server - An origin server is designed to consume the incoming requests that modify the value of the resources of any representation. You may think of it as a container that holds the requested representations of the resources. It uses a server connector to receive and respond to requests. Web servers like Apache Tomcat & Microsoft IIS are examples of the origin server.
  2. User Agent - A user agent initiates a request at the client end. It uses a client connector to initiate such requests and becomes the recipient of the response. Web browsers like Mozilla, Chrome, etc are classic examples of user agents. They act as the starting point of any service requested by the user and render the response as sent by the servers.
  3. Gateway - A gateway is an intermediary imposed by the network. It provides service encapsulation like data translation(compression), performance enhancement(load balancing), or security enforcement(encryption). It acts as both the client and the server to facilitate the exchange of requests and responses with possible data translation. Examples are Squid, NGINX, CGI, etc.
  4. Proxy - It is also an intermediary to the requests made by the client for some service or some resources. Similar to the gateway, it provides an interface for encapsulation of services like load balancing, encryption, or compression. Examples of proxy are CERN proxy, Netscape proxy, CGI proxy, etc.

What are Data Elements?

The uniform interface between the components of REST architectural style distinguishes it from all other network-based architectures. It makes all the interactions between the client and the server unified through a fixed set of operations. Data elements and their state form the key aspect of REST architectural elements. The components interact by exchanging the representation of the current or desired state of data elements.

Types of data elements

REST identifies six data elements as described below-

Resource

A resource is any addressable information on the server. It is a conceptual mapping to a set of entities and not the data itself. This mapping can either be static or temporal. A static resource is one that remains unchanged over a long period of time like a web page address. Alternatively, a temporal resource keeps changing with time, as the weather information about a city.

Resource Identifier

A resource identifier uniquely identifies a resource also known as URI. The URIs and resources follow a many-to-one relationship. It means that a resource can have multiple URIs providing differing information about the resource. An example of resource identifier Bookstore API by ToolsQA. The resource identifier for getting the list of available books is- https://bookstore.toolsqa.com/BookStore/v1/Books On accessing the above resource identifier you will be able to see the resources, i.e the list of books present in the database.

Resource Metadata

It describes the different properties of a resource by providing additional information like its location or the alternate resource identifier. It categorizes the resource and gives information about it.

Representation

Representation is the state of a resource and is data plus the metadata which explains the data. In a real sense, we do not directly send or receive the resource. Rather, we request and receive the representation of resources. A representation can either be a document, a file, or even an HTTP message entity. XML and JSON are the most popular resource representations. In our example of bookstore API, the resource representation is in JSON format.

JSON Representation of data

Representation Metadata

This data element, resource metadata, describes the format type of the response body. This helps in the interpretation of data at the client end. The representation metadata consists of the different headers used in the request and response. We have explained all the header types in our previous posts on HTTP request and HTTP response. But let us still quickly see what all headers are included as representation metadata in our example API.

Representation metadata as headers

As can be seen, The resource request defines the content-type as a JSON and also specifies the content-length to set the limit. The response headers also identify the additional information for the response like the User-Agent, Connection, Accept-Encoding, etc

Control Data

It defines the purpose of messages exchanged between the client and the server such as the requested action and response meaning. It also helps parameterize requests and override the connecting elements' default behaviour. For example, control data can modify the cache behaviour of a request or the response. Additionally, the data corresponding to a certain condition like the last modification date(If-Modified-Since) or if it matches a certain parameter(If-Match) can be fetched.

Key Takeaways

  • REST services are architectures with three main elements viz, Connectors, Components & Data Elements along with a few constraints.
  • Connectors work as an interface, to communicate between the components.
  • Components are the endpoints. They are the hardware or software programs used for sending and receiving requests.
  • Data elements are the key aspect of REST architectural elements. They facilitate the exchange of data through resource and their representations using the resource identifier. They also use additional information through metadata and control data.
What is Rest Api?
What is Rest Api?
Previous Article
Getting started with Rest Assured
Getting started with Rest Assured
Next Article

Similar Articles

Feedback