Configure API filters (functions)

Updated at:
Copy as MD

API filters let you attach custom logic to an API without modifying its core implementation. A pre-filter runs before the API processes an incoming request, letting you reshape parameters, validate input, or inject context. A post-filter runs after the API returns results, letting you transform, enrich, or mask the response.

How API filters work

DataService Studio supports Aviator and Python functions. Use DataService Studio to create functions, test, publish, and use functions, and publish functions. After a function is published, associate it with an API to use it as a filter. This lets you handle different query requirements and adapt to business scenarios without modifying the core API logic. For details, see Use a function as an API filter.

  • A pre-filter preprocesses an API's request parameters before the API handles the call.

  • A post-filter transforms an API's returned results after the API handles the call.

For code examples of common scenarios, see Best practices: Use an Aviator function as a filter.

Requirements

  • The pre-filter and post-filter for an API must use the same function type: either both Aviator or both Python. Mixing function types for the pre-filter and post-filter of the same API is not supported.

  • Aviator functions must run in an exclusive resource group for DataService Studio for security and performance reasons.

    • When editing or testing a function, attach an exclusive resource group for DataService Studio to it. For more information, see Create a function.

    • When developing an API, if you enable a filter and associate a target function, attach an exclusive resource group for DataService Studio to the API. For more information, see Generate an API in the codeless UI.

Limitations

  • The filter feature requires DataWorks Basic Edition or a later version.

  • Python functions are being upgraded. You cannot create, clone, or publish new Python functions. Use the Aviator function type instead. For more information, see Create an Aviator function.