Sitemap
Devin Munasinghe

Devin Munasinghe

Software Engineering Undergraduate @ SLIIT

Press enter or click to view image in full size

What is REST API?

5 min readMay 15, 2022

What is API?

Application programming interface (API) is a set of definitions and protocols for developing and integrating software applications. Simply, (API) is a software middleman that allows two applications to communicate with one another. When you use apps like Facebook, Twitter, or Youtube you are always dealing with an API.

How does API work?

To understand the process of an API we can use a simple example.

Think about you going to a restaurant to ask to order a burger for you. Then the waiter takes your order and takes it to the kitchen. The kitchen prepares your order, and after the order is ready the waiter brings back the order for you to preserve.

In this example, you are like the client or the application and the waiter is like an API that takes your request and takes it to the kitchen, and after the order is ready, he delivers the meal as the response. Moreover, the kitchen act like a server that prepares your order.

In below diagram illustrates the process of API more clearly.

Press enter or click to view image in full size

What is REST API?

Now we have discussed what is API and also the process of an API as well. A REST API is an API that follows the REST, or representational state transfer, architectural style’s design principles. REST APIs are sometimes referred to as RESTful APIs because of this.

Dr. Roy Fielding defined REST API Design in his doctoral dissertation in 2000. It’s noteworthy for its incredibly flexible layer. REST can handle many sorts of calls, return different data formats, and even change fundamentally with the correct implementation of hypermedia because data is not tied to methods and resources.

For developers, REST provides a great amount of flexibility and freedom. REST APIs have become a popular approach for linking components and applications in a microservices architecture because of their flexibility.

REST design principles

Get Devin Munasinghe’s stories in your inbox

Join Medium for free to get updates from this writer.

An API is, at its most basic level, a mechanism that allows one application or service to access a resource within another application or service. The client is the application or service that performs the access, while the server is the application or service that has the resource.

Some APIs impose a rigorous structure on developers, such as SOAP or XML-RPC. REST APIs, on the other hand, can be written in almost any programming language and support a wide range of data formats. The one and only requirement is that they have to deal with the following six REST design principles which are also known as architectural constraints

  1. Uniform Interface

No matter where the request comes from, all API requests for the same resource should appear the same. The REST API should make sure that the same data, such as a user’s name or email address, is associated with only one uniform resource identifier (URI). The resources should not be excessively huge, but they should contain all of the information that the client would want.

2. Client- server decoupling

Client and server apps must be totally independent of one another in REST API design. Only the URI of the requested resource should be known by the client program; it cannot communicate with the server application in any other way. Similarly, a server application should not change the client program other than to provide the required data to it over HTTP.

3. Statelessness

REST APIs are stateless, which means that each request must include all of the data required to process it. REST APIs, in other words, do not require any server-side connections. Any data connected to a client request cannot be stored by server programs.

4. Cacheability

Resources should be cacheable on the client or server side wherever possible. Server answers must also provide information about whether the supplied resource can be cached. The goal is to increase client-side performance while boosting server-side scalability.

5. Layered system architecture

The calls and responses in REST APIs pass through several tiers. As a general rule, don’t expect the client and server programs to communicate directly. In the communication loop, there could be several different intermediaries. REST APIs must be developed in such a way that neither the client nor the server can tell whether they are communicating with the end application or with an intermediary.

6. Code on demand

REST APIs typically deliver static resources, but responses can also contain executable code in some circumstances (such as Java applets). The code should only run on demand in these situations. However, this is optional.

How REST API works?

REST APIs use HTTP requests to conduct standard database activities within a resource, such as creating, reading, updating, and deleting records (also known as CRUD). A REST API would, for example, utilize a GET request is used to obtain a record, a POST request is used to create one, a PUT request to update one, and a DELETE request to delete one. In API calls, you can utilize any HTTP method. A well-designed REST API is akin to a website that runs in a web browser and supports HTTP.

The state of a resource at any particular instant, or timestamp, is known as the resource representation. This information can be delivered to a client in virtually any format including JavaScript Object Notation (JSON), HTML, XLT, Python, PHP, or plain text. JSON is popular because it’s readable by both humans and machines — and it is programming language-agnostic.

In REST API calls, request headers and parameters are especially significant since they contain identifying information like metadata, authorizations, uniform resource identifiers (URIs), caching, cookies, and more. Within properly-designed REST APIs, request and response headers, as well as standard HTTP status codes, are used.

Press enter or click to view image in full size

That is all about API and Also REST API. Hope you enjoy it..😎

--

--

Devin Munasinghe
Devin Munasinghe

Written by Devin Munasinghe

Software Engineering Undergraduate @ SLIIT