This topic describes how to test, publish, and use a function.
Prerequisites
A function is created and saved. For more information, see Manage functions.
Limits
You can test a function only as a workspace owner or a RAM user to which the Workspace Administrator, Develop, or O&M role is assigned. For more information, see the "Add a RAM user to a workspace as a member and assign roles to the member" section in the Manage permissions on workspace-level services topic.
Step 1: Test the function
Go to the DataService Studio page.
Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose . On the page that appears, select the desired workspace from the drop-down list and click Go to DataService Studio.
In the left-side navigation pane of the Service Development page, find the function that you want to test and double-click the name of the function.
On the configuration tab of the function, click Test in the upper-right corner.
In the Function Test dialog box, specify Input parameters and click OK.
You can view the running status on the Execution results tab at the bottom. If the test fails, perform modifications based on the error message and test the function again.
Step 2: Publish the function
After you test a function, you can publish the function.
In the left-side navigation pane of the Service Development pane, find the function that is tested and double-click the name of the function.
On the configuration tab of the function, click Submit in the top toolbar.
In the right-side navigation pane of the configuration tab of the function, click Version. On the Version tab, find the version that is in the Can Be Published state and click Publish in the Actions column.
NoteAfter the function is published, you can click Version in the right-side navigation pane of the configuration tab of the function to view the publishing record. You can also click Version Details or Roll Back in the Actions column.
Step 3: Use the function
Scenarios
If you use a function as a prefilter for an API, the function preprocesses the request parameters of the API when the API is called.
If you use a function as a post-filter for an API, the function processes and reconstructs the responses of the API when the API is called.
Limits
If you use one or more functions as prefilters for an API and one or more functions as post-filters for the API, you must use the same type of function as the filters. You can use either Aviator or Python functions. You cannot use different types of functions as the filters for an API.
The feature of using a Python function as a filter is being optimized. You cannot create, clone, or publish new Python functions.
Use a function as a filter for an API
In the Service Development pane, click the .
Find the API and double-click the API. The configuration tab of the API appears.
In the right-side navigation pane, click Filter.
On the Filter tab, select Use Pre-filter or Use Post-filter based on your business requirements. The default value of Function Type is Aviator Function. Then, select one or more functions from the drop-down list next to the Use Pre-filter or Use Post-filter check box. If you select multiple functions, the functions process request parameters or responses based on the sequence in which the functions are selected.
NoteYou can specify one or more functions as a filter to process the request parameters or responses of an API.
If the function that you want to use is not displayed in the drop-down list next to the Use Pre-filter or Use Post-filter check box, check whether the function is published. If the function is not published, publish the function. You can also create and publish a new function. For more information, see Publish a function.
Click Preview Responses Returned by API Operation and check whether the processing results of the selected functions meet your expectations.