Create a New REST Web Method

The sub-branches beneath a newly created Web Service (as mentioned in Create a New Web Service - REST) allow you to create a Web Method.

 

To Add a New Web Method

  1. Right-click on a sub-branch beneath a Web Service and select "Add Web Method" as shown below.

Adding a New Web Method

 

-OR-

 

Select a sub-branch beneath a Web Service, then click on the Add Web Method button, shown below,  in the Edit section of the Home button in the Workbench.

 

Add Web Method button

  1. This opens the Web Method properties in the right-pane of the Workbench as shown below. Enter a Name in the top text entry field.

 

General Settings Tab

This tab is used to configure common properties related to the Web Method.

 

General Settings

 

General Settings

Return Schema

When loading the schema of an API method, Workbench will call the method with the configured parameter values and analyze the result to understand the shape of the returned data. If the API returns an array, Workbench will look at the first item in the array and assume that all other items have the same schema. The data received from the service is anonymized and displayed in the Schema field.

 

Some APIs might return data that has a different schema depending on the parameters used for the call, or even an array of items that have different properties among different items. In such cases, the schema detection feature would not work because the schema is loaded once with the configured parameters and, for arrays, it is determined by looking at the first item of the array only.

 

The Enable Dynamic Schema checkbox can be used to support these scenarios: when dynamic schema is enabled, the Web Services runtime will determine the schema on the fly based on the current return value from the API. If the return value is an array with items having different properties, the Web Services runtime will generate the schema by merging all the different properties from the array items.

 

Note: dynamic schema is computationally more intensive, which may lead to reduced runtime performance. It is recommended to use it only when necessary, and to use fixed schema (by using the Load Schema button) in all other cases.

Parameters Tab

The Parameters tab allows to configure parameters for the Web Method.

 

Parameters Tab

 

Parameters

 

Click the "+ Click here to add new item" link to add a new default parameter. You can then enter a Name, Value, and Kind (using the pulldown menu, select from Query String or POST Body, Cookie, URL Segment, HTTP Header, Query String, or Request Body) and select whether the parameter will be Sensitive (by clicking the checkbox within that column).

 

When a parameter is marked as Sensitive, it will be obscured in the Workbench UI so that its value cannot be read. It will also be removed in runtime from the point name. For security reasons, unchecking the Sensitive checkbox will clear the parameter value.

 

As described above, the supported parameter types are:

To simplify runtime usage, Request Body parameters also support virtual parameters. Consider the following example, where an HTTP POST is made to create a new social media post on an API:

 

Web Method to create a new post

 

Associated Request Body Parameter

 

Typically, a request body parameter will appear in the point name when browsed in runtime, carrying the whole JSON as its value:

 

Runtime Point Name with JSON

This leads to lengthy point names which are difficult to modify in runtime, especially when the JSON is complex.

 

With virtual parameters, it is possible to parameterize the Request Body so that only selected parts are changeable in runtime. Following the example above, assume we want to parameterize just the title and the body of the post that we want to create. We can go ahead and replace the values with a name of a parameter, prefixed with the special @ character:

 

Substituting virtual parameters in the Request Body

 

Then, we can proceed to create individual parameters for title and body, with Kind set to Query String or POST Body:

 

Creating Virtual Parameters

 

The final result is that in runtime, the Request Body parameter will not be a part of the point name anymore. We will see the title and body parameters instead:

 

Virtual Parameters in the Point Name

Data Refresh Tab

The Data Refresh tab is used to configure refresh behavior for the Web Method.

 

Data Refresh

 

Refresh Options

 

The Refresh Type combo-box allows to configure how the results received by the server are refreshed. The options are:

*See How the Web Services Runtime requests and caches data section for more details on how caching and requesting data from web services works.

 

Refresh Triggers

 

If a Refresh Type of "By Triggers" is selected, you can click on the + Click here to add new item link to create a new Refresh Trigger. Once activated, you can enter a Tag Name in the text entry field or click on the button to open the Data Browser and navigate to your selected Tag Name.

 

  1. Once you have completed making edits to the Web Method Instance, click Apply to save your settings and Close to exit.

Multiple Triggers can be added to refresh the REST Web Method on different conditions.

 

See Also:

Create a New Folder

Create a New Web Service

Web Services Overview

Create a New REST Web Manipulator