DataService Studio in Alibaba Cloud DataWorks lets you expose a processed table as an API and publish the API to API Gateway for other business applications to query. This topic uses a sample scenario to generate, configure, test, and publish an API for a website user profile table. Authorizing and calling the published API are covered in separate topics.
Prerequisites
You must have created an exclusive resource group for DataService Studio or configured CU quotas for a serverless resource group. Verify that the StarRocks compute resource is connected to the resource group.
You must have completed the steps in Process data to obtain the data in the website user profile table.
Create a user profile API service
After you synchronize and process the data, a table named ads_user_info_1d_${data_source_type} is generated. To make this table available to other business applications, use the DataWorks DataService Studio feature, which generates an API service in Wizard Mode or Script Mode.
Step 1: Generate the user profile API
The operations in this example are performed in DataService Studio. You can generate the API in either Wizard Mode or Script Mode. This example uses Wizard Mode.
Log on to the DataWorks console. In the target region, click Data Analysis and Service > DataService Studio in the left-side navigation pane. Select a workspace from the drop-down list and click Go to DataService Studio.
Create an API service.
On the DataService Studio page, click the
icon and choose Create API > Generate API. In the Generate API dialog box, select Wizard Mode to generate the API.
For more information about generating an API in Script Mode, see Create an API in the code editor.
Step 2: Configure the user profile API
Configure the API details.
In Wizard Mode, use the following settings to create an API data service for a StarRocks data source. The following table describes the parameters.
NoteThe API data service does not support Hive data sources.
Module
Parameter
Description
Example
Table
Data Source Type
Select the type of the data source. The available types are listed in the drop-down list.
This example uses a StarRocks data source.
Table
Data Source Name
Select an existing data source.
Use the
Doc_StarRocks_Storage_Compute_Tightly_01business data source.Table
Data Source Environment
Select the environment of the data source. Valid values: Production Environment and Development Environment.
Select Production Environment.
Table
Data Table Name
Select the table that the API uses.
Select the
ads_user_info_1d_StarRockstable.Select Parameters
Pagination for Return Results
Enables or disables pagination for the returned results. This setting affects the request parameters and the response parameters of the API. In the resource group section of the right-side navigation bar, you can set the maximum number of data records for a single request based on the resource group type. For more information, see Create an API from a data source (API Gateway).
Do not enable Pagination for Return Results.
Select Parameters
Set as Req Param
Set one or more fields in the table as request parameters.
Set the
dtpartition field as Request Parameters.Select Parameters
Set as Resp Param
Set one or more fields in the table as response parameters.
Set all fields in the
ads_user_info_1d_StarRockstable as Response Parameters.Select Parameters
Sorting Fields
Optional. To sort the results by a field, first select the field in the parameter list.
No sorting is applied.
Configure the resource group.
After you configure the API in Wizard Mode, click Resource Group for DataService Studio in the right-side navigation bar to configure service resources. For more information, see Configure a resource group for an API.
Select the resource group based on the resources that you already have:
If you already purchased an exclusive resource group for DataService Studio, use it directly.
(Recommended) If no resource group is available, purchase a general-purpose serverless resource group. For more information, see Use a serverless resource group.
ImportantIf a newly purchased serverless resource group is dimmed and cannot be selected, allocate a quota to the Data Services module for that resource group. For more information, see Allocate CU quotas to a task.
The following table describes the parameters that this example configures.
Module
Parameter
Description
Resource Group Type
Scheme
Select Exclusive Resource Group for DataService Studio.
Resource Group Type
Exclusive Resource Group for DataService Studio
Select a serverless resource group or an exclusive resource group for DataService Studio.
Environment Configuration
Timeout
Set to 30,000 ms.
Environment Configuration
Maximum Number of Data Records for a Single Request
Set to 2,000 records.
Step 3: Test and publish the API
Test the API to check whether the parameters returned by the generated API service meet your expectations. For more information, see Test an API.
After you complete the configuration, click the save icon
to save the API, and then click the test icon
to go to the API testing page.In the Test API dialog box, enter values for the request parameters.
Click Start Test to test the API. After you click Start Test, the execution log appears in the Request Details section on the right, and the response appears in the Response section. If the returned
errCodeis0anderrMsgissuccess, the API test call is successful, and thedatafield contains the query results.
Publish the API. Publishing deploys the API to API Gateway and generates an online endpoint. For more information, see Test, publish, and manage API versions.
After the API passes the test, click the submit icon
on the API editing page to submit the API. A new API version is generated. Click the Version tab on the right to view the submitted API versions. When a version is in the Ready to Publish state, the Actions column provides options such as Publish, Deprecate, Version Details, and Rollback.Click Publish to publish the API service.
After the API is published, manage it by clicking Service Management in the version management section, or by choosing Service Management > Manage APIs > Published APIs. For more information, see Manage and maintain APIs.
What to do next
After the API is published, you can authorize and call the API. For more information, see Authorize an API and Call an API.