DataWorks DataService Studio allows you to consume data by using APIs and can provide data for business that uses APIs to receive data. This topic provides a sample scenario to describe how to use APIs in DataWorks DataService Studio to consume data.
Prerequisites
An exclusive resource group for DataService Studio is created, or a data service quota is configured for your serverless resource group. In addition, your MaxCompute computing resource is connected to your resource group.
Data is processed. A website user profile table is obtained.
Create a user profile API
After data is synchronized and processed, a data table named ads_user_info_1d_${Data source type} is generated. The data table must be provided for business that can receive data by using APIs. DataWorks allows you to create APIs in DataService Studio. You can use the codeless user interface (UI) or code editor to create APIs.
Step 1: Create a user profile API
In this example, operations are performed by using the API feature of DataService Studio.
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.
Create an API.
In the Service Development pane of the DataService Studio page, click the
icon and choose . In the Generate API dialog box, configure the parameters to create an API by using the codeless UI. NoteYou can create an API by using the codeless UI or code editor. In this example, an API is created by using the codeless UI.
For information about how to create an API by using the codeless UI, see Create an API by using the codeless UI.
For information about how to create an API by using the code editor, see Create an API by using the code editor.
Step 2: Configure the user profile API
Configure details for the user profile API.
After you create a user profile API by using the codeless UI, you can configure the parameters described in the following table to configure details about the API. In this example, a user profile API that uses a StarRocks data source is configured. For information about how to create an API by using the codeless UI, see Create an API by using the codeless UI.
Section
Parameter
Description
Example
Select Table
Datasource Type
The data source type.
NoteAPI-based data services do not support Hive data sources. You can view the data source types that are supported when you configure the Datasource Type parameter.
In this example, StarRocks is selected.
Datasource Name
The data source that is added.
In this example, the business data source
Doc_StarRocks_Storage_Compute_Tightly_01is used.Datasource Env.
Production
Development
In this example, Production is selected.
Table Name
The table that needs to be used by the API.
In this example, the table
ads_user_info_1d_StarRocksis selected.Select Parameters
Pagination for Return Results
Specifies whether to paginate the returned results. The setting of this parameter affects the configuration of request parameters and response parameters.
If you turn on Pagination for Return Results, click Resource Group in the right-side navigation pane, and configure the Maximum Number of Data Records for a Single Request parameter on the Resource Group tab based on the resource group type that you specify. For more information, see Configure the API.
In this example, Pagination for Return Results is turned off.
Set as Req Param
The field that you want to specify as a request parameter. You can specify multiple fields as request parameters.
In this example, the partition field
dtis specified as a request parameter.Set as Resp Param
The field that you want to specify as a response parameter. You can specify multiple fields as response parameters.
In this example, all fields in the table
ads_user_info_1d_StarRocksare specified as response parameters.Sort field
The configurations in the Sort field section are optional. If you want to sort the data that the API returns based on a specific field, find the field and click Add in the Add to field sort column. After you click Add, the field is added to the Sort field section.
In this example, no fields are added to sort the data that the API returns.
Configure a resource group for DataService Studio.
After the API is configured, click Resource Group in the right-side navigation pane to configure a resource group. The following table describes the parameters that you can configure. For more information, see Configure a resource group for DataService Studio.
Section
Parameter
Description
Resource Group Type
Scheme
Select Exclusive Resource Group for DataService Studio.
Exclusive Resource Group for DataService Studio
Select an exclusive resource group for DataService Studio or a serverless resource group (recommended).
ImportantIf you have purchased an exclusive resource group for DataService Studio, you can directly select it.
If no resource group is available, we recommend that you purchase a serverless resource group. For more information, see Create and use a serverless resource group.
If the serverless resource group that you purchased is dimmed and cannot be selected, you must configure compute unit (CU) quotas for the resource group for DataService Studio. For more information, see Manage quotas.
Environment Configuration
Function Timeout
Set the value to 30000. Unit: milliseconds.
Maximum Number of Data Records for a Single Request
Set the value to 2000.
Step 3: Test and publish the API
Test the API to check whether the response parameters that are returned by the API meet your expectations. For more information, see Test an API.
After the configuration is complete, click the
icon in the top toolbar to save the API and click the
icon in the top toolbar to go to the Test APIs dialog box. In the Test APIs dialog box, specify values for all request parameters of the API.
Click Test to test the API.
Publish the API to API Gateway. After the API is published to API Gateway, an online calling address is generated. You can perform the following operations to publish the API to API Gateway. For more information, see Publish an API.
If the test on the API is successful, click the
icon in the top toolbar on the configuration tab of the API to submit the API. After the API is submitted, a version is generated for the API. To view information about all versions that are generated for the API, click Version in the right-side navigation pane.
Click Publish in the Actions column of a version to publish the API of this version.
After the API of this version is published, click Service Management in the Actions column of the version to manage the API. Alternatively, click Service Management in the top navigation bar and manage the API on the Published APIs tab of the Manage APIs page. For more information, see the topics in the Manage and maintain APIs directory.
What to do next
After the API is published, you can call the API and grant other workspaces the permissions to call the API. For more information, see Call an API and Grant permissions to call an API.