RESTful Services

Jamisulochana
5 min readMay 12, 2022

Businesses are an increasing number of deploying their offerings at the internet, in the form of web applications, message-based services and recently REST services. This document provides overview of REST. REST is used to increase performance, scalability, simplicity, modifiability, visibility, portability, and reliability. This is achieved through REST principles such as a client–server architecture, statelessness, use of a layered system, support for code on demand, and using a uniform interface.

The term representational state transfer was introduced in 2000 by Roy Flelding in his doctoral dissertation. The term is intended to evoke an image of how a well-designed Web application behaves. Design behind the Web architecture can be described by an architectural style consisting of the set of constraints applied to elements within the architecture. By analyzing the impact of each and every constraint as it is added to the evolving style, can identify the properties induced by the Web’s constraints. It is a network of Web resources where the user advances through the application by selecting links, resulting in the next resource’s representation being transferred to the client and rendered for the user.

According to the REST principles, REST interfaces depend completely on Uniform Resource Identifiers (URI) for resource detection and Hypertext Transfer Protocol (HTTP) for message transfer.

. The HTTP verbs (GET, POST etc.) are used to define the type of operation that should be performed on the selected resource. Possibly due to HTTP’s features general understandability, REST has become a standard way for offering a service on the Web. REST is an architectural style, provided without standard specifications.

REST ignores the information of factor implementation and protocol syntax which will consciousness on the jobs of components, the limitations upon their interplay with different components, and their interpretation of tremendous records elements

REST style is an abstraction of the architectural elements inside a distributed hypermedia system. REST ignores component implementation information and protocol syntax which will consciousness on the roles of components, the constraints upon their interaction with other different components. It encompasses the essential constraints upon components, connectors and data that define the basis of the Web architecture, and accordingly the essence of its behavior as a network-based application.

REST components communicate by transferring a representation of a resource in a format matching one of an evolving set of standard data types, selected dynamically based on capabilities or desires of recipient and nature of resource. Whether the representation is withinside the same format as the raw source, or is derived from the source, remains hidden at the back of the interface.

Following table summarized REST’s data elements.

Resources and Resource Identifiers

Resource is a key point of information in REST. Any information that can named as a resource. All the concept that target of an author’s hypertext reference must fit for definition of a resource. a document or image, a temporal service, a collection of other resources is few examples. Also resource is a conceptual mapping to a set of entities.

a resource identifier used by REST to identify the particular resource involved in an interaction between components.

REST connectors provide a generic interface for gaining access to and manipulating the value set of a resource, regardless of how the membership function is defined or the type of software that is handling the requests. resource identifier assigned by naming authority and making it possible to reference the resource.

Representations

REST components perform actions on a resource by using a representation to capture current state of that resource. Also, it transfers representation between components. A representation is a sequence of bytes. Commonly used but less precise names for a representation are document, file, HTTP message entity, instance etc. Control data is used to override default behavior of some connecting elements and to parameterize requests. Such as cache behavior can be modified by control data included in the request or response message.

Connectors

REST have various kind of connector types, to encapsulate the activities of accessing resources and transferring resource representations. Connectors give an abstract interface for component communication, enhancing simplicity by providing a clean separation of concerns and communication mechanisms. Also, all the REST interactions are stateless. All the request contains all of the information necessary for a connector to understand the request.

The primary connector types of REST are client and server. Client initiates communication by making a request. Then ,server listens for connections and responds to requests in order to supply access to its services. A component may include client connector and server connector.

Components

Following are the example for REST Components.

· origin server

· gateway

· proxy

· user agent

HTTP Verbs

Each HTTP verbs used for the corresponding behavior.

GET — Fetch a resource

PUT — Replace existing resource

POST — Insert new resource

DELETE — Remove a resource

PATCH — Update Resource

OPTIONS — Get all allowed options

HEAD — Get only the response header

Best Practices

● Nouns over verbs.

● Do not use GET method to alter the state.

● Use plural nouns.

● Represent sub resources.

● Use HTTP status codes for errors.

● Use links to other related resource where needed.

● Provide additional functionalities like filtering, pagination, sorting and field selection via query parameters.

● Version the API.

● Always expose via HTTPS.

HTTP Codes

● 200 — OK

● 201 — Created

● 202 — Accepted

● 204 — No content

● 301 — Moved permanently

● 302 — Found

● 304 — Not modified

● 400 — Bad request

● 401 — Unauthorized

● 403 — Forbidden

● 404 — Not found

● 405 — Method not allowed

● 409 — Conflict

● 412 — Precondition failed

● 500 — Internal server error

● 502 — Bad gateway

● 503 — Service unavailable

--

--

Jamisulochana

Bsc(Hons) Degree in Information Technology, specializing in Software Engineering at Sri Lanka Institute of Information Technology