What is REST?

Representational State Transfer (REST) is an architectural style consisting of a coordinated set of constraints applied to components, connectors, and data elements, within a distributed hypermedia system. REST ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements.

REST has been applied to describe desired web architecture, to identify existing problems, to compare alternative solutions, and to ensure that protocol extensions would not violate the core constraints that make the Web successful. Fielding used REST to design HTTP 1.1 and Uniform Resource Identifiers (URI).

The REST architectural style is also applied to the development of Web services, as an alternative to other distributed-computing specifications such as SOAP.

REST allows that resources will have different representations, like- text, xml, json etc. The rest client can ask for specific representation via the HTTP protocol (content negotiation).

The properties of the REST architectural style are:

Performance
Scalability of component interactions
Simplicity of interfaces
Modifiability of components to meet changing needs (even while the application is running)
Visibility of communication between components by service agents
Portability of component deployment
Reliability

REST Supports only HTTP protocol and all HTTP methods –  like  GET, POST, PUT, DELETE

REST uses these operations and other existing features of the HTTP protocol. For example, layered proxy and gateway components perform additional functions on the network, such as HTTP caching and security enforcement.

The architectural properties of REST :

Client–server

A uniform interface separates clients from servers. This separation of concerns means that, for example, clients are not concerned with data storage, which remains internal to each server, so that the portability of client code is improved. Servers are not concerned with the user interface or user state, so that servers can be simpler and more scalable. Servers and clients may also be replaced and developed independently, as long as the interface between them is not altered.

Stateless

The client–server communication is further constrained by no client context being stored on the server between requests. Each request from any client contains all of the information necessary to service the request, and session state is held in the client. Important to note is that the session state can be transferred by the server to another service such as a database to maintain a persistent state for a period of time and allow authentication. The client begins sending requests when it is ready to make the transition to a new state. While one or more requests are outstanding, the client is considered to be in transition. The representation of each application state contains links that may be used the next time the client chooses to initiate a new state-transition.

Cacheable

As on the World Wide Web, clients can cache responses. Responses must therefore, implicitly or explicitly, define themselves as cacheable, or not, to prevent clients reusing stale or inappropriate data in response to further requests. Well-managed caching partially or completely eliminates some client–server interactions, further improving scalability and performance.

Layered system

A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. Intermediary servers may improve system scalability by enabling load-balancing and by providing shared caches. They may also enforce security policies.

Example – How REST services URI looks like:

If you navigate below the examples subdirectory to the library resources subdirectory, you’ll find the following resources for the application:

  • BooksResource: Represents a list of books
  • BookResource: Represents a specific book
  • AuthorsBookResource: Represents a list of Booksfor a specific Authors
  • AuthorResource: Represents a specific Author

Recall that to address a resource in REST you specify its URI. However, to communicate with a resource, you also need to specify a communication protocol such as HTTP. Here are the URIs and HTTP methods that correspond to the resources in the library application:

 

RESOURCE
URI PATH
HTTP METHODS
BooksResource
/books
GET
BookResource
/books/{bookid}
GET, PUT, DELETE
AuthorsBookResource
/authors/{authorid}/books
GET, POST
AuthorResource
/authors/{authorid}
GET, PUT, DELETE
Gopal Das
Follow me

Leave a Reply

Your email address will not be published. Required fields are marked *