Data service APIs
The DataService Studio module in DataWorks lets you expose data through APIs for your business applications. This topic demonstrates how to create a data service API by using a sample scenario.
Prerequisites
-
You have purchased an Exclusive Resource Group for DataService Studio or configured a DataService Studio quota for a serverless resource group. You have also verified the network connectivity between the resource group and your MaxCompute compute resources.
-
You have completed the Process data step and obtained the website user profile table data.
Create a user profile API
Synchronizing and processing your data generates the ads_user_info_1d table. To expose this data through an API, use the API feature in DataService Studio. You can generate an API in either Wizard Mode or Script Mode.
Step 1: Generate the user profile API
Perform the following steps in DataService Studio.
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to DataService Studio.
-
Create an API.
On the DataService Studio page, click the
icon and choose . In the Generate API dialog box, select Wizard Mode.NoteYou can generate an API in Wizard Mode or Script Mode. This example uses Wizard Mode.
-
To learn how to generate an API in Wizard Mode, see Generate an API from a data source (API Gateway).
-
To learn how to generate an API in Script Mode, see Generate an API in Script Mode.
-
Step 2: Configure the user profile API
-
Configure the API.
In Wizard Mode, configure the following parameters to create a data service API for a MaxCompute data source. For more information, see Generate an API from a data source (API Gateway).
Module
Parameter
Description
Example
Table
Data Source Type
Select the data source type.
NoteData service APIs do not support Hive data sources. The available data source types are limited to the options in the drop-down list.
This example uses a MaxCompute data source.
Data Source Name
Select an existing data source.
Use your business data source.
Data Source Environment
-
Production Environment
-
Development Environment
Select Production Environment.
Data Table Name
Select the table for the API.
Select the
ads_user_info_1dtable.Select Parameters
Pagination for Return Results
Enable or disable pagination for the results. This setting affects the request and response parameters of the API.
In the Service Resource Group panel on the right, you can set the maximum number of data records for a single request based on the resource group type. For more information, see Generate an API from a data source (API Gateway).
Disable Pagination for Return Results.
Set as Req Param
Select fields to use as request parameters.
Set the
dtpartition field as a Request Parameters.Set as Resp Param
Select fields to use as response parameters.
Set all fields in the
ads_user_info_1dtable as Response Parameters.Sorting Fields
The sort field is optional. If you want to sort by a field, first select the desired field from the list of parameters.
Do not sort.
-
-
Configure the service resource group
After configuring the API, click Resource Group for DataService Studio in the right-side navigation pane to configure its resources. The following table describes the parameters. For more information, see Configure a service resource group for an API.
Module
Parameter
Description
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.
Important-
If you have purchased an Exclusive Resource Group for DataService Studio, you can use it directly.
-
If you do not have a resource group, we recommend purchasing a general-purpose serverless resource group. For more information, see Use a serverless resource group.
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 Data Services usage of the resource group. For more information, see Allocate CU quotas to tasks.
Environment Configuration
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 it returns the expected response parameters. For more information, see Test an API.
-
After completing the configuration, click the
icon to save the API, and then click the
icon to open the test page. -
In the API test dialog box, enter values for the request parameters.
-
Click Start Test to start the API test.
-
-
Publishing an API adds it to API Gateway and generates an online endpoint. For more information, see Test, publish, and manage versions of an API.
-
After the API passes the test, click the
icon on the API editing page to submit the API. A new API version is generated. In the right-side panel of the API details page, click the Version tab to go to the version management page. Find the version with the Publishable status, such as v1. -
Click Publish to publish the API.
-
After the API is published, you can click Service Management in the version management section or navigate to . For more information, see Manage and maintain APIs.
-
Next steps
After the API is published, you can authorize and call it. For more information, see Authorize an API and Call an API.