You are very familiar with the word REST API irrespective of the technology you are working with. Let’s see it’s architecture and functionality. Before that, what is API? API stands for Application Programming Interface. It provides a set of rules using which two applications can communicate. REST stands for Representational State Transfer. It is used to build web services that are lightweight, maintainable, and scalable. It is based on HTTP which is the foundation of the web.
Key Constraints of REST API
Following are the key constraints that make up the REST API by creating a complex, powerful and flexible API.
It is fundamental to design any RESTful system. It simplifies and decouples the architecture thus, enabling each part to evolve independently. Below are the 4 interface constraints
- Identification of resources
- Manipulation of resources through representations
- Self-descriptive messages
- Hypermedia as the engine of application state
The client and server are independent. A client can be any application and server can be a database where the data is stored. As client and server are independent, enhancing one application will not make any changes to other application. In this way, both can be enhanced quickly. The communication between the client and server will always be initiated by the client. It will be in the form of request and response. Client requests some data from the server and the server sends the data in response.
In this, the state is stored on the client but not on the server. It reduces memory requirements and keeps the application scale-able. Each request contains all the information required to complete the request.
When a client sends the request to server, server returns the response to the client. The client can only receive the response but, cannot tell whether it is directly connected to end server or intermediary server. There may be multiple layers between the client and end server to provide a caching layer, a load-balancing layer, security layer, or other functionality.
Every response contains information about whether they are cache-able or not. Client cache can store the data, which reduces the number of interactions with the server enhancing the performance.
Example of REST API in Magento
Some of the REST APIs are Gmail, Facebook, Instagram, Twitter, Dropbox, Github, Salesforce, Magento and so on. Let’s see how to communicate with Magento using REST API.
Let’s see how to connect to Magento using REST API.
Invoking Magento REST API via POSTMAN
Below are the steps to be followed:
- In order to login to Magento with REST API first create request in the below format:
- Provide ‘Website URL’ in place of ‘website URL’ and provide Magento Admin Username and password in the body.
- Select the method ‘POST’ and put the request in the Postman and click on the ‘Send’ button. If the credentials are correct, you will get ‘access token’ in response from Magento.
- Now, we use this access token to perform further communication with Magento. We can get the data (GET), post the data (POST), update the data (PUT) and delete the data (DELETE) in Magento with REST API.
- Below is the URL to ‘POST’ the Customer details to Magento
- Now, put the above access token in the Header with Key as ‘Authorization’ and Value as ‘Bearer Accesstoken’ as shown in the below screenshot.
- Now, send the above request to Magento with the ‘POST’ method.
- In a similar way, we can perform an update and delete the data from Magento.
When to use REST
We have seen the principles of REST API and how to communicate with REST API. Let us see the scenarios where we can use it.
- Limited resources and bandwidth: As REST API is lightweight, it is used in instances where network bandwidth is a constraint.
- Statelessness: REST should be used when a state of the information need not be maintained from one request to another.
- Caching: REST can be used when a lot of requests to be cached.
How we can help
Our team can help you customize and integrated Salesforce as per your business process. Read about our Salesforce Integration Services. Reach out to us for a free assessment of your business needs.