Making HTTP Requests Through REST API Browser (Beta)

In this document, we will see how we can make different HTTP requests through REST API Browser (Beta) in Astera Centerprise.

Making a GET Request

To make a GET request, drag and drop the relevant GET request object from the REST API Browser (Beta) onto the designer window and pass your required PetId into it.

17

In this scenario, we want to get the info for pet with the PetId 3. For that, we will select the GET request ‘Find Pet by ID’ and pass the relevant PetId using a ConstantValue object.

image-20200420232028527

To explore the REST Client object for this method, right-click on its header and select Properties.

5

This will open the REST API Client (Beta) screen where the connection info of your API is defined.

image-20200415172128155

Shared REST API Connection– shows the name of your REST API Connection. You can select any shared REST API Connection you want to use from the drop-down list. The connections for all the APIs that have been imported in the project will be shown here

1

HTTP METHOD – shows the HTTP method of your call

Resource – shows what information you want to get from a specific API. It is a part of the Url of request sent

Content Type – shows the type of your content

All the above information is configured according to the request method that you have selected.

Click Next to proceed to the Parameters screen.

21

Here, you will see the following options:

Name: It contains the name of the parameter.

Rest Parameter Location: It tells which parameter is being used to make the call. There are three parameters which Centerprise supports:

  1. URL: This parameter is necessary to be specified.
  2. Query: This parameter may or may not be optional and can work as a filter while processing records.
  3. Header: This parameter is generally used for authentication purpose.

Click Next to proceed to the REST API Client Output Layout (Beta) screen where you can build the Response Layout of your API. There are two ways in which you can generate the output layout:

  1. The first one is by providing sample text by clicking on ‘Generate Layout by providing Sample Text’ option.
  2. The other way to do that is by running a request by clicking the ‘Generate Layout by running Request’ option.

2

Click Next to proceed to the Rest API Pagination Options (Beta).

23

Making a POST Request

Now, let’s try posting a pet to the petstore. For that, we will drag the ‘Add a new pet to the store’ request from the REST API Browser (Beta) panel and drop it on to the dataflow designer.

27

We will pass the required parameters to the POST request object using a Variables object.

image-20200415153345334

Now, right-click on the REST API Client (addPet) object and select Preview Output.

image-20200415152721762

You can see that the ‘HTTPStatusCode’ is 200 which means that the REST API has successfully carried out whatever action the client requested. Let’s verify it by making a GET request for the same PetId which we posted.

image-20200415154040570

You can see that a GET request for PetId 1 has returned us the same information which we had posted.

4

Making a DELETE Request

Now, Let’s try making a DELETE request. For that, we will first make a GET request to see if that pet exists on the petstore or not and try to delete that. We will pass PetId 5 using a ConstantValue object.

image-20200415153741346

Right-click on the REST API Client (getPaidById) object and select Preview Output.

3

It has given the details of the pet with PetId 5, and the status shows that the pet is available on the pet store.

To delete this pet record, we will drag and drop the ‘Deletes a pet’ request from the REST API Browser (Beta) panel on to dataflow designer.

34

Pass PetId 5 to the DELETE request object using a ConstantValue object.

image-20200415154206358

Right-click on the REST API Client object and select Preview Output. You can see that it has returned ‘HTTPStatusCode’ 200 which means a successful execution.

image-20200415154517085

Let’s verify it by making a GET request again and check if pet with PetId 5 has been deleted or not.

image-20200415153741346

Right-click on the REST API Client (getPetById) object and select Preview Output.

38

You can see that Centerprise has returned error 404 which means that there is no pet found with PetId 5 and the pet record has been successfully deleted from petstore API.

Working with APIs That Require Authentication

Let’s try making an API request that needs authentication. We’ll be making a GET request object using Adafruit’s API.

First, import the API by using the relevant import source. In this case, we will import using the Json/Yml Url import source.

image-20200421102704612

You will see that all the APIs present on Adafruit’s URL have been populated in the REST API Browser (Beta).

40

Now you need to authenticate Adafruit’s APIs to use them in your dataflow. Without authentication, you will get an error. To authenticate an API, go to the Project Explorer and double click on the API’s .sact file under the Shared Connection node. In this case, we will double-click on Adafruit’s .sact file.

Untitled

Adafruit’s .sact file will open on the designer. Now, right click on shared action file’s header and select Properties.

50

This will open the REST API Connection window, where you can configure the settings to authenticate Adafruit’s API.

image-20200421102925157

Select the Security Type and specify the relevant details.

image-20200421103035427

You can see that the Security Type has been specified as API Key which means that the Adafruit’s API uses ‘API Key’ as its authentication method.

To see the authentication methods supported in Centerprise, click on the Security Type drop-down list.

48

You will see the following options:

  1. O Auth 2
  2. API Key
  3. Basic Authentication
  4. Bearer Token
  5. No Authentication

Click OK. Now that the API has been authenticated, we can work with the API and make HTTP requests.

To make a GET request, drag and drop the ‘Get feed by key’ object from the REST API Browser (Beta) on to the dataflow designer.

41

It requires two parameters: username and feed_key. We will pass the values to these parameters either by using a source object via mapping it or by specifying the parameter value in the default value column in the properties of ‘getFeed’ object.

image-20200415175550365

In this case, we have provided the username through a constant value object. Now let’s specify the feed_key in the Default Value column in the properties of the getFeed object.

Right click on the REST API Client (getFeed) and select Properties. Go to the Parameters screen and specify the feed_key value in the Default Value column.

43

Click Next to proceed to the REST API Client Output Layout (Beta) screen. Here, you can see the Response Layout of your selected method.

image-20200415175327259

Click Next to proceed to the the Service Options screen.

image-20200415151600757

Now, right click on the REST API Client (getFeed) object and select Preview Output.

6

You can see that Centerprise has returned the feed information by providing the required parameters.

Centerprise’s Server API

Now, let’s understand how to authenticate Centerprise’s Server API. The first step is to import a Custom API and provide the required credentials.

1

Click OK.

A node will be added in the REST API Browser (Beta) panel.

2

Now you can add HTTP methods for server operations by adding requests.

(To learn how to add a request in a Custom API, click here)

image-20200514142732800

Although we have successfully added a node for our Custom API, we are yet to authenticate it. Centerprise’s server API uses ‘Bearer Token’ authentication.

To authenticate your custom API, go to the .Sact file in the Shared Connections.

3

A new tab by the name of ServerInfo.Sact will open. Here, you can see an object where you can configure the authentication settings for the API.

4

Right-click on the header of ServerInfo object and go to Properties.

5

This will open the REST API Connection (Beta) screen. Select the Security Type as ‘Bearer Token.’

zdgfd

Provide the User Name, Password, and Token URL for Bearer Token and click OK.

zdgfd

Now, that we have authenticated our custom API, we can make the required HTTP requests.

Drag and drop the Jobs object from the REST API Browser (Beta) panel.

jobs

Right-click on Jobs object header and select Preview Output.

11

This is how your output would look like:

12

This concludes making HTTP requests through REST API Browser (Beta) in Astera Centerprise.