All Products
Search
Document Center

DataWorks:Use a function as a filter for an API

Last Updated:Aug 08, 2023

This topic describes how to use a function as a prefilter or post-filter for an API.

Prerequisites

A function is created. For more information, see Create an Aviator function and Create a Python function.

Background information

On the DataService Studio page, you can create, test, and publish a function. Then, you can associate the function with an API, and use the function as a filter to process the request parameters or responses of the API to perform complex queries based on your business requirements. For more information about the sample code that shows how to use an Aviator function as a filter for an API in common scenarios, see Best practices of using Aviator functions as filters.

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

  1. In the Service Development pane, click the business process to which the desired API belongs.

  2. Find the API and double-click the API. The configuration tab of the API appears.

  3. 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.

    Note
    • You 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.

  4. Click Preview Responses Returned by API Operation and check whether the processing results of the selected functions meet your expectations.