Preface – This post is part of the SAP ABAP OData Tutorial series.
Table of Contents
In our previous article we have discussed what is an API. There are different types of API calls e.g. Simple Object Access Protocol (SOAP), Remote Procedure Call (RPC) and Representational State Transfer (REST). All these API calls have same purpose i.e. to transfer data securely among two or more systems. In this article we will only explore the Restful Web Services.
What is REST
As stated earlier, REST stands for Representational State Transfer. It is a simple way of sending and receiving data between client and server. It doesn’t require any software or standards to transfer data. It has a predefined structure to do the API call. Developers just need to use the predefined way and pass their data as JSON payload.
Attributes of Restful Web Services
A RESTful web service has following six constraints/attributes:
- Client-Server: It is a very important aspect of REST APIs. A REST API follows client-server architecture and these both should be separate. It means both the server and client can not be same server. In case it is same, you will receive CORS error.
- Stateless: In REST, all calls are treated as a new call and any previous call state will not give any advantage to the new call. Hence during each call, it is required to maintain all the necessary authentication and other information.
- Cache: A REST API encourages the browser and server caching process to enhance its processing speed.
- Uniform Interface: The interface between the Client and Server remains uniform, hence any changes in either side will not affect the API functionality. This help in development of Client and Server system independently.
- Layered System: REST allows usage of layered structure in server side i.e. you can have data on different server, authentication on different server while the API on different server. The client will never come to know that it is getting the data from which server.
- Code on Demand: It is an optional feature of REST API where server can even send executable code to the client that can run directly during run time.
Methods in Restful Web Services
Using Restful web services, we can perform these basic four operations:
- GET: This method is used to get a list of data from server.
- POST: This method is used to post/create a new record in server.
- PUT: This method is used to update an existing record of server.
- DELETE: This method is used to perform deletion of a record at server side.
Note: Just calling the above method doesn’t guarantee that the operations will be performed until these operations are implemented at the server side too.
Advantages of Restful Web Services
Following are the major advantages of a RESTful API:
- They are simpler and flexible to implement
- It supports greater variety of data formats e.g. JSON, XML, YAML, etc.
- It is faster and provides better performance
Disadvantages of Restful Web Services
Although REST services tend to provide multiple benefits, still it has given demerits:
- To implement state related query the REST Headers are required which is a clumsy work
- The PUT and DELETE operations are not usable through firewalls or in some browsers.