DataService Studio in DataWorks supports data consumption through APIs, which lets you supply data to various business applications. This topic uses a sample scenario to describe how to consume data using an API service in DataWorks.
Prerequisites
You have created an exclusive resource group for DataService Studio or configured a data service quota for a serverless resource group. You must also ensure that your MaxCompute computing resource is properly connected to the resource group.
You have completed the Process data step and obtained the website user persona table data.
Create a user persona API service
After you synchronize and process data, a data table named ads_user_info_1d is generated. You can use this table to provide data to business applications through APIs. DataService Studio in DataWorks provides an API feature that lets you generate an API service in the Codeless UI or Code Editor.
Step 1: Generate a user persona API
This example describes the operations required to use the API feature in 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 service.
On the DataService Studio page, click the
icon and choose . In the Generate API dialog box, select Wizard Mode to generate the API.NoteYou can generate an API in Wizard Mode or Script Mode mode. This topic uses the Wizard Mode as an example.
For more information, see Generate an API in the codeless UI.
For more information, see Generate an API in the code editor.
Step 2: Configure the user persona API
Configure details.
After you create a user persona API, configure the parameters to implement an API data service for a MaxCompute data source. For more information, see Generate an API in the codeless UI.
Section
Parameter
Configuration
Example
Select Table
Datasource Type
Select the data source type.
NoteAPI-based data services do not support Hive data sources. The supported data source types are displayed in the drop-down list.
This example uses a MaxCompute data source.
Datasource Name
Select a created data source.
Use the business data source.
Datasource Env
Production
Development
Select Production
Table Name
Select the table to be used by the API.
Select the
ads_user_info_1dtable.Select Parameters
Pagination for Return Results
Specifies whether to enable paging for the returned results. This setting affects the request and response parameters of the API.
In the service resource group settings in the right-side navigation pane, you can set the maximum number of data records for a single request based on the resource group type. For more information, see Configure an API.
Turn off Pagination for Return Results.
Set as Req Param
Set one or more fields in the table as request parameters.
Set the
dtpartition field as a request parameter.Set as Resp Param
Set one or more fields in the table as response parameters.
Set all fields in the
ads_user_info_1dtable as response parameters.Sort Field
This parameter is optional. To sort the results by a field, first select the field from the parameter list.
No sorting is configured.
Configure a service resource group
After you configure the API in the codeless UI, click Resource Group in the right-side navigation pane to configure service resources. The following table describes the parameters. For more information, see Configure a service resource group for an API.
Section
Parameter
Configuration
Resource Group Type
Scheme
Exclusive Resource Group for DataService Studio.
Exclusive Resource Group for DataService Studio
Select a serverless resource group (recommended) or an exclusive resource group for DataService Studio.
ImportantIf you have purchased an exclusive resource group for DataService Studio, you can use it directly.
If no resource group is available, purchase a general-purpose serverless resource group. For more information, see Use serverless resource groups.
If a newly purchased serverless resource group is grayed out and cannot be selected when you configure the service resource group, you must allocate a quota for the DataService Studio usage of the resource group. For more information, see Allocate CU quotas to tasks.
Environment Configuration
Function Timeout
Set the value to 30000 ms.
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 verify that the returned parameters meet your expectations. For more information, see Test an API.
After the configuration is complete, click the
icon to save the API, and then click the
icon to open the API test page.In the Test APIs dialog box, enter values for the request parameters.
Click Test to test the API.
Publish the API to API Gateway to generate an online endpoint. For more information, see Publish an API.
After the API passes the test, on the API editing page, click the
icon to submit the API. A new API version is generated. You can click Version on the right side of the page to view information about the submitted API version.
Click Submit to publish the API service.
After the API is published, you can manage the published API by clicking Service Management in the version management section or by navigating to . For more information, see Manage and maintain APIs.
Next steps
After the API is published, you can perform other operations, such as authorizing and calling the API. For more information, see Authorize an API and Call an API.