29 May Understanding REST APIs
Communication with REST APIs is the method that different software use to integrate and pass information to each other. It can be described as set of rules that allow programs to talk to each other.
According to Wikipedia ´representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services. The term REST is used to describe any interface between systems, which directly uses HTTP to obtain data, or to indicate the execution of operations in any format (XML, JSON, etc.).
Basically, REST APIs are used to connect two different software and to do this effectively, developers must document these APIs and indicate which methods they are going to leave available for external programs to connect and extract information.
Let’s take Facebook as an example. Some of the methods that Facebook uses in its APIs enable other applications to connect and obtain all the friends of a specific user.
REST relies on HTTP requests
The great advantage offered by REST API technology over others such as SOAP is that they use the same structure as the HTTP protocol to request and transfer data between different applications.
When we write an address in our web browser´s location bar, it sends a GET request to the web server, and this in turn sends back a response (REQUEST-RESPONSE).
For example, we open the browser and type https://www.auraquantic.com/
It then connects to the web server via a TCP/IP connection, and sends a request of this type:
|GET /index.html HTTP/1.1|
- In the first line we specify the name of the resource we want to access “index.html”, and the protocol version we use HTTP/1.1
- In the second line we add the HOST to indicate the name of the domain we’re going to access. This header is always included, but you can add others.
- The third line is a placeholder that is like the one we enter when we press the Enter key.
- Once the web server receives the request, depending on the configuration, it will issue a response like this:
|Date: Tue mar 2020 04:33:33 GMT|
|Server: Microsoft – IIS/10.0|
|Content-Type: text/html; charset=uft-8|
|Text can reach up to a 1000 bytes|
- The first line tells us the version of the HTTP protocol.
- The following lines are the headers with the following data:
- Date and time of the connection.
- Type of web server that contains the resources we want to access. In this case Microsoft’s Internet Information Server.
- Content-Type indicates that the file is of type txt/html, and the character set is uft-8.
- Content-Length tells us the number of bytes to be transmitted.
- Next we include a return.
- Finally, we transfer the content until it reaches a 1000 bytes.
The most common HTTP methods are as follows:
|Method||Description||*Interact with the server|
|GET||Request some data from the web server||No|
|POST||Update data on the web server||Yes|
|PUT||Add new data on the web server||Yes|
|PATCH||Partially modify a resource||Yes|
|DELETE||Delete data from the web server||Yes|
*Interact means that the request will make changes to the server. The clearest example is when we modify a record from a web form and update the database on the web server.
How do we use a REST API
To explain this, we will use the example of integrating of a low-code application development platform (LCAP) such as AuraPortal with an RPA, in this case UiPath.
Both technologies are used for process automation, but their area of influence is different. Process automation with robots aims to reduce human intervention, especially for repetitive tasks. Whereas a low-code tool, like AuraPortal, can automate end-to-end processes and provide additional capabilities including monitoring, analysis, decision management and report generation for continuous optimization.
In many cases adding an RPA as an automated system within a workflow is beneficial for the application and makes it easier for the people involved.
Obviously to do this we need both applications to be able to connect and exchange information. For this to be possible we need to know the characteristics of the UiPATH REST API and create a connector using the tools inside AuraPortal.
In the UiPath Orchestator API Guide web page there is documentation of the methods that UiPath makes available for developers to connect and carry out operations with its API.
Any type of operation that we initiate with the RPA will require authentication. In the Authentication section it is said that the UiPath authentication system uses bearer tokens (OAuth 2.0 authorization standard), and we must make a POST request to the URI https://cloud.uipath.com/api/account/authenticate using our credentials.
As shown in this example, the server returns the token in “result”
Creating the connector with AuraPortal
Once we have the information, we must create a connector in AuraPortal by following the instructions in the API manual.
In order to do so we must access the Connectors section in Structure and click on the ‘Create Connector’ button. The next step is giving a name to the connector, selecting the function Rest – Custom Web Services, and the class _Rest – Custom Web Services.
To configure the connector, we click on Next, and select the Publish option so that the connector can be used within an automated process. We’ll also need set the appropriate date and encoding.
After which we can start defining the connector’s operations. As mentioned before, any operation we perform with the UiPath API will require an authentication token, so logically the first step is to set up an authentication operation to obtain the token.
We must follow the steps in the API documentation to create a POST type operation, which targets the UiPath authentication URL, and in Request we indicate the following values:
|«tenancyName» : «whichever_is_applicable»,|
|«usernameOrEmailAddress» : «your_username»,|
|«password» : «whichever_is_applicable»|
In Response we will assign to the parameter “result” an AuraPortal dictionary term to save the token.
When we execute a new operation with the API we must include this token in the Request Headers.
And follow the steps specified in the UiPath documentation to create the new operations.
Why do we need a REST API
One of the greatest advantages of offering a REST API is that other developers can create alternative services and reach market niches that the original product could not.
We can say that this is a way to find allies that will help the expansion of a brand.
Companies that make good use of this are Evernote, Dropbox, eBay, Twitter, Instagram, Facebook. A large number of their users reach them through other applications via APIs.
In terms of the technology used, it should be noted that REST APIs are based on the HTTP communication protocol, which is undoubtedly the most widespread at present.