What is actually a REST API ?

Ravithamara Wijayabandu
3 min readMay 30, 2021

--

A REST API is also known as RESTful API. It was defined by Roy Fielding. REST means Representational State Transfer. Most popular websites and cloud-based companies use REST API for their applications such as Facebook, twitter, google. It is an application program interface that supports interactions with RESTful web services. A way to communicate over HTTP in a similar way to web browsers and servers. REST is a set of architectural constraints/principles. Remind that REST is not a protocol. REST APIs are faster, lightweight, maintainable and scalable. That is why they are suitable for mobile and web app development. There is no need of installing any libraries or extra packages to use RESTful APIs. Developers have the ability to implement REST in different ways. REST can handle multiple types of calls. A client request made with REST API transfers current state of the resource to endpoint. This representation can be transferred in various data formats via HTTP. REST can return format types like XML, JSON, Python, YAML, XLT, PHP etc. REST APIs are considered much easier than SOAP (Simple Object Access Protocol) APIs. Because SOAP APIs are awfully slow and heavy.

There are 6 rules that an API to be RESTful.

Client-Server

· It is simple. Client sends a request to server and server response to the client. Client and server should be separate from each other to evolve individually. Client-server architecture managed by requests through HTTP

Cache

· There should be Cacheable data that streamlines interactions. Caching happens when media is on a client’s device visiting website. When client visits to a certain site cached data is loaded from storage. It decreases page load time. Response should indicate that the data can be stored up to a certain time. This will reduce server usage and interactions

Code on demand

· Ability to send executable code from server to client in response.

Uniform Interface

· Uniform interface should be there between components to allow independent evolution. It provides the way to client to talk to the server in single language.

Stateless

· REST API should not rely on data being stored on the server. Calls can be made independently. Each client request must contain all the data necessary to respond. Stateless transfer supports to reduce the amount of sever memory

Layered model

· Each layer has a specific functionality and responsibility. Client does not need to know the other end which it is communicating with. Additional layers should not affect client-server interactions.

RESTful web service request contains endpoint URL, HTTP method, HTTP headers, body data

.Endpoint URL example : https://mydomain/user/123?format=json

.HTTP methods (GET, POST, PUT/PATCH, DELETE) example

GET request to /user/ returns a list of users on system

POST request to /user/123 creates user with ID

--

--