All Products
Search
Document Center

DataWorks:Test an API

Last Updated:Jan 22, 2024

After an API is created, if you want to publish the API to API Gateway, you must test the API in DataService Studio to check whether the request parameters and return values of the API meet your business requirements. You can also test a published API. This topic describes how to test an API that is being developed and an API that is published.

Background

When you test APIs, the shared resource group for DataService Studio is used to access data sources or backend services to call APIs. You are charged for the resource group based on the number of API calls and the execution time of the API calls. For more information about the billing details, see DataService Studio.

Test an API that is being developed

You can test an API that is being developed on the Service Development tab of the DataService Studio page. Before you perform the test, you must create or register the API.

  1. Log on to the DataWorks console. In the left-side navigation pane, click DataService Studio. On the page that appears, select the desired workspace from the drop-down list and click Go to DataService Studio.

  2. On the Service Development tab, find the API that you want to test in the Business Processes section and double-click the API name. On the configuration tab of the API, click Test in the upper-right corner.

    测试

  3. Test the API.

    1. In the Test APIs dialog box, configure all request parameters of the API.

    2. (Recommended) Select Save the correct response example automatically in the lower-left corner.

      If you select Save the correct response example automatically, DataWorks saves the current test result as a sample success response.

      Note
      • When the system tests an API, sample error responses and error codes are automatically generated. However, the system does not automatically generate sample success responses. The sample success response is an important reference for API callers. To generate a sample success response, you must select Save the correct response example automatically.

      • If the response contains sensitive data that needs to be masked, you must edit the response to mask the data.

  4. Click Test to trigger the API test.

    • You can view information that is displayed in the Request Details and Response Details sections on the right side of the Test APIs page.

    • The API call latency value is the latency of the current API request. The value is used to evaluate the API performance. If the latency is high, we recommend that you optimize the query logic or data source.

    • If the API test fails, check the error message, modify the API settings, and then retest the API.

Test an API that is published

You can test an API that is published on the Service Management tab of the DataStudio Service page. Before you perform the test, you must submit and publish the API. For more information, see Publish an API.

  1. On the DataService Studio page, click Service Management in the upper-right corner.

  2. In the left-side navigation pane, click Test APIs.

  3. Select the API that you want to test from the drop-down list, and confirm that all request parameters of the API are configured.

    请求参数

  4. Click Test to trigger the API test. You can view information that is displayed in the Request Details and Response Details sections on the right side of the Test APIs page.

    Note

    On the Test APIs page, you can only test published APIs. You cannot update sample success responses for APIs.

What to do next

After you perform a test on an API that is being developed, you can publish the API. This way, other users can call the API. For more information about how to publish an API, see Publish an API.